feat(pwsh): debug prompt

This commit is contained in:
Jan De Dobbeleer 2022-03-15 20:16:04 +01:00 committed by Jan De Dobbeleer
parent 6e3c1af164
commit d11c39b620
4 changed files with 15 additions and 1 deletions

View file

@ -29,10 +29,11 @@ var (
// printCmd represents the prompt command
var printCmd = &cobra.Command{
Use: "print [primary|secondary|transient|right|tooltip|valid|error]",
Use: "print [debug|primary|secondary|transient|right|tooltip|valid|error]",
Short: "Print the prompt/context",
Long: "Print one of the prompts based on the location/use-case.",
ValidArgs: []string{
"debug",
"primary",
"secondary",
"transient",
@ -86,6 +87,8 @@ var printCmd = &cobra.Command{
Plain: plain,
}
switch args[0] {
case "debug":
fmt.Print(eng.PrintExtraPrompt(engine.Debug))
case "primary":
fmt.Print(eng.PrintPrimary())
case "secondary":

View file

@ -40,6 +40,7 @@ type Config struct {
ValidLine *ExtraPrompt `json:"valid_line,omitempty"`
ErrorLine *ExtraPrompt `json:"error_line,omitempty"`
SecondaryPrompt *ExtraPrompt `json:"secondary_prompt,omitempty"`
DebugPrompt *ExtraPrompt `json:"debug_prompt,omitempty"`
Palette color.Palette `json:"palette,omitempty"`
format string

View file

@ -275,11 +275,14 @@ const (
Valid
Error
Secondary
Debug
)
func (e *Engine) PrintExtraPrompt(promptType ExtraPromptType) string {
var prompt *ExtraPrompt
switch promptType {
case Debug:
prompt = e.Config.DebugPrompt
case Transient:
prompt = e.Config.TransientPrompt
case Valid:
@ -297,6 +300,8 @@ func (e *Engine) PrintExtraPrompt(promptType ExtraPromptType) string {
return template
}
switch promptType { // nolint: exhaustive
case Debug:
return "[DBG]: "
case Transient:
return "{{ .Shell }}> "
case Secondary:

View file

@ -67,6 +67,11 @@ function global:Initialize-ModuleSupport {
$env:POSH_TRANSIENT = $false
return
}
if (Test-Path variable:/PSDebugContext) {
$standardOut = @(&$omp prompt print debug --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" 2>&1)
$standardOut -join "`n"
return
}
$errorCode = 0
Initialize-ModuleSupport
Set-PoshContext