mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
refactor(cli): isolate debug command
This commit is contained in:
parent
34a7d917a8
commit
6e3c1af164
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
|
@ -56,7 +56,7 @@ body:
|
||||||
id: logs
|
id: logs
|
||||||
attributes:
|
attributes:
|
||||||
label: Log output
|
label: Log output
|
||||||
description: Please copy and paste the output generated by `Write-PoshDebug (PowerShell)`, or `oh-my-posh prompt print debug --shell uni --config="$POSH_THEME"` for other shells.
|
description: Please copy and paste the output generated by `Write-PoshDebug (PowerShell)`, or `oh-my-posh prompt debug` for other shells.
|
||||||
render: shell
|
render: shell
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
|
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -63,7 +63,6 @@
|
||||||
"program": "${workspaceRoot}/src",
|
"program": "${workspaceRoot}/src",
|
||||||
"args": [
|
"args": [
|
||||||
"prompt",
|
"prompt",
|
||||||
"print",
|
|
||||||
"debug",
|
"debug",
|
||||||
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json"
|
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json"
|
||||||
]
|
]
|
||||||
|
|
59
src/cli/prompt_debug.go
Normal file
59
src/cli/prompt_debug.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||||
|
|
||||||
|
*/
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"oh-my-posh/color"
|
||||||
|
"oh-my-posh/console"
|
||||||
|
"oh-my-posh/engine"
|
||||||
|
"oh-my-posh/environment"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// debugCmd represents the prompt command
|
||||||
|
var debugCmd = &cobra.Command{
|
||||||
|
Use: "debug",
|
||||||
|
Short: "Print the prompt in debug mode",
|
||||||
|
Long: "Print the prompt in debug mode",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
env := &environment.ShellEnvironment{
|
||||||
|
CmdFlags: &environment.Flags{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
env.Init(true)
|
||||||
|
defer env.Close()
|
||||||
|
cfg := engine.LoadConfig(env)
|
||||||
|
ansi := &color.Ansi{}
|
||||||
|
ansi.Init("shell")
|
||||||
|
writerColors := cfg.MakeColors(env)
|
||||||
|
writer := &color.AnsiWriter{
|
||||||
|
Ansi: ansi,
|
||||||
|
TerminalBackground: engine.GetConsoleBackgroundColor(env, cfg.TerminalBackground),
|
||||||
|
AnsiColors: writerColors,
|
||||||
|
}
|
||||||
|
consoleTitle := &console.Title{
|
||||||
|
Env: env,
|
||||||
|
Ansi: ansi,
|
||||||
|
Template: cfg.ConsoleTitleTemplate,
|
||||||
|
}
|
||||||
|
eng := &engine.Engine{
|
||||||
|
Config: cfg,
|
||||||
|
Env: env,
|
||||||
|
Writer: writer,
|
||||||
|
ConsoleTitle: consoleTitle,
|
||||||
|
Ansi: ansi,
|
||||||
|
Plain: plain,
|
||||||
|
}
|
||||||
|
fmt.Print(eng.PrintDebug(cliVersion))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { // nolint:gochecknoinits
|
||||||
|
promptCmd.AddCommand(debugCmd)
|
||||||
|
}
|
|
@ -29,11 +29,10 @@ var (
|
||||||
|
|
||||||
// printCmd represents the prompt command
|
// printCmd represents the prompt command
|
||||||
var printCmd = &cobra.Command{
|
var printCmd = &cobra.Command{
|
||||||
Use: "print [debug|primary|secondary|transient|right|tooltip|valid|error]",
|
Use: "print [primary|secondary|transient|right|tooltip|valid|error]",
|
||||||
Short: "Print the prompt/context",
|
Short: "Print the prompt/context",
|
||||||
Long: "Print one of the prompts based on the location/use-case.",
|
Long: "Print one of the prompts based on the location/use-case.",
|
||||||
ValidArgs: []string{
|
ValidArgs: []string{
|
||||||
"debug",
|
|
||||||
"primary",
|
"primary",
|
||||||
"secondary",
|
"secondary",
|
||||||
"transient",
|
"transient",
|
||||||
|
@ -57,16 +56,11 @@ var printCmd = &cobra.Command{
|
||||||
Shell: shell,
|
Shell: shell,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
debug := args[0] == "debug"
|
env.Init(false)
|
||||||
env.Init(debug)
|
|
||||||
defer env.Close()
|
defer env.Close()
|
||||||
cfg := engine.LoadConfig(env)
|
cfg := engine.LoadConfig(env)
|
||||||
ansi := &color.Ansi{}
|
ansi := &color.Ansi{}
|
||||||
shell := env.Shell()
|
ansi.Init(env.Shell())
|
||||||
if debug {
|
|
||||||
shell = "shell"
|
|
||||||
}
|
|
||||||
ansi.Init(shell)
|
|
||||||
var writer color.Writer
|
var writer color.Writer
|
||||||
if plain {
|
if plain {
|
||||||
writer = &color.PlainWriter{}
|
writer = &color.PlainWriter{}
|
||||||
|
@ -92,8 +86,6 @@ var printCmd = &cobra.Command{
|
||||||
Plain: plain,
|
Plain: plain,
|
||||||
}
|
}
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "debug":
|
|
||||||
fmt.Print(eng.PrintDebug(cliVersion))
|
|
||||||
case "primary":
|
case "primary":
|
||||||
fmt.Print(eng.PrintPrimary())
|
fmt.Print(eng.PrintPrimary())
|
||||||
case "secondary":
|
case "secondary":
|
||||||
|
|
|
@ -114,7 +114,7 @@ Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||||
function global:Write-PoshDebug {
|
function global:Write-PoshDebug {
|
||||||
$omp = "::OMP::"
|
$omp = "::OMP::"
|
||||||
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||||
$standardOut = @(&$omp prompt print debug --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" 2>&1)
|
$standardOut = @(&$omp prompt debug --config="$config" 2>&1)
|
||||||
$standardOut -join "`n"
|
$standardOut -join "`n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue