oh-my-posh/src/cli/debug.go

65 lines
1.5 KiB
Go
Raw Normal View History

2022-03-15 12:02:46 -07:00
package cli
import (
"fmt"
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/engine"
2022-11-09 11:27:54 -08:00
"oh-my-posh/platform"
2022-03-21 23:41:36 -07:00
"oh-my-posh/shell"
"time"
2022-03-15 12:02:46 -07:00
"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.",
2022-03-15 12:02:46 -07:00
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
startTime := time.Now()
2022-11-09 11:27:54 -08:00
env := &platform.Shell{
Version: cliVersion,
2022-11-09 11:27:54 -08:00
CmdFlags: &platform.Flags{
2022-03-15 12:02:46 -07:00
Config: config,
Debug: true,
2022-11-02 07:05:04 -07:00
PWD: pwd,
2022-11-03 06:10:35 -07:00
Shell: shellName,
2022-03-15 12:02:46 -07:00
},
}
env.Init()
2022-03-15 12:02:46 -07:00
defer env.Close()
cfg := engine.LoadConfig(env)
ansi := &color.Ansi{}
ansi.InitPlain()
2022-10-13 11:01:51 -07:00
writerColors := cfg.MakeColors()
2022-03-15 12:02:46 -07:00
writer := &color.AnsiWriter{
Ansi: ansi,
2022-03-21 23:41:36 -07:00
TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground),
2022-03-15 12:02:46 -07:00
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(startTime, cliVersion))
2022-03-15 12:02:46 -07:00
},
}
func init() { //nolint:gochecknoinits
2022-11-02 07:05:04 -07:00
debugCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
2022-11-03 06:10:35 -07:00
debugCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
2022-11-02 03:48:19 -07:00
RootCmd.AddCommand(debugCmd)
2022-03-15 12:02:46 -07:00
}