mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
refactor(ansi): do not allow plain GOOS override
This commit is contained in:
parent
ce7b7f1501
commit
77d5c9ed95
|
@ -59,7 +59,7 @@ Exports the config to an image file using customized output options.`,
|
|||
defer env.Close()
|
||||
cfg := engine.LoadConfig(env)
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
writerColors := cfg.MakeColors()
|
||||
writer := &color.AnsiWriter{
|
||||
Ansi: ansi,
|
||||
|
|
|
@ -34,7 +34,7 @@ var debugCmd = &cobra.Command{
|
|||
defer env.Close()
|
||||
cfg := engine.LoadConfig(env)
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain(env.GOOS())
|
||||
ansi.InitPlain()
|
||||
writerColors := cfg.MakeColors()
|
||||
writer := &color.AnsiWriter{
|
||||
Ansi: ansi,
|
||||
|
|
|
@ -148,8 +148,8 @@ func (a *Ansi) Init(shellName, goos string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *Ansi) InitPlain(goos string) {
|
||||
a.Init(shell.PLAIN, goos)
|
||||
func (a *Ansi) InitPlain() {
|
||||
a.Init(shell.PLAIN, "")
|
||||
}
|
||||
|
||||
func (a *Ansi) GenerateHyperlink(text string) string {
|
||||
|
|
|
@ -96,7 +96,7 @@ func TestFormatText(t *testing.T) {
|
|||
}
|
||||
for _, tc := range cases {
|
||||
a := Ansi{}
|
||||
a.InitPlain("")
|
||||
a.InitPlain()
|
||||
formattedText := a.formatText(tc.Text)
|
||||
assert.Equal(t, tc.Expected, formattedText, tc.Case)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestGetTitle(t *testing.T) {
|
|||
Folder: "vagrant",
|
||||
})
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
ct := &Title{
|
||||
Env: env,
|
||||
Ansi: ansi,
|
||||
|
@ -117,7 +117,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
|
|||
HostName: "",
|
||||
})
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
ct := &Title{
|
||||
Env: env,
|
||||
Ansi: ansi,
|
||||
|
|
|
@ -67,7 +67,7 @@ func (b *Block) Init(env platform.Environment, writer color.Writer, ansi *color.
|
|||
|
||||
func (b *Block) InitPlain(env platform.Environment, config *Config) {
|
||||
b.ansi = &color.Ansi{}
|
||||
b.ansi.InitPlain(b.env.GOOS())
|
||||
b.ansi.InitPlain()
|
||||
b.writer = &color.AnsiWriter{
|
||||
Ansi: b.ansi,
|
||||
TerminalBackground: shell.ConsoleBackgroundColor(env, config.TerminalBackground),
|
||||
|
|
|
@ -211,7 +211,7 @@ func (e *Engine) renderBlock(block *Block) {
|
|||
ansi := e.Ansi
|
||||
if e.Env.Shell() == shell.BASH {
|
||||
ansi = &color.Ansi{}
|
||||
ansi.InitPlain(e.Env.GOOS())
|
||||
ansi.InitPlain()
|
||||
}
|
||||
prompt := ansi.CarriageForward()
|
||||
prompt += ansi.GetCursorForRightWrite(length, block.HorizontalOffset)
|
||||
|
@ -307,7 +307,7 @@ func (e *Engine) print() string {
|
|||
// in bash, the entire rprompt needs to be escaped for the prompt to be interpreted correctly
|
||||
// see https://github.com/jandedobbeleer/oh-my-posh/pull/2398
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain(e.Env.GOOS())
|
||||
ansi.InitPlain()
|
||||
prompt := ansi.SaveCursorPosition()
|
||||
prompt += ansi.CarriageForward()
|
||||
prompt += ansi.GetCursorForRightWrite(e.rpromptLength, 0)
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestPrintPWD(t *testing.T) {
|
|||
Shell: "shell",
|
||||
})
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
engine := &Engine{
|
||||
Env: env,
|
||||
Config: &Config{
|
||||
|
@ -102,7 +102,7 @@ func engineRender() {
|
|||
defer testClearDefaultConfig()
|
||||
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
writerColors := cfg.MakeColors()
|
||||
writer := &color.AnsiWriter{
|
||||
Ansi: ansi,
|
||||
|
|
|
@ -33,7 +33,7 @@ func runImageTest(config, content string) (string, error) {
|
|||
}
|
||||
defer os.Remove(file.Name())
|
||||
ansi := &color.Ansi{}
|
||||
ansi.InitPlain("")
|
||||
ansi.InitPlain()
|
||||
image := &ImageRenderer{
|
||||
AnsiString: content,
|
||||
Ansi: ansi,
|
||||
|
|
|
@ -18,15 +18,15 @@ func New(flags *platform.Flags) *Engine {
|
|||
env.Init()
|
||||
cfg := LoadConfig(env)
|
||||
ansi := &color.Ansi{}
|
||||
ansi.Init(env.Shell(), env.GOOS())
|
||||
|
||||
var writer color.Writer
|
||||
if flags.Plain {
|
||||
ansi.InitPlain(env.GOOS())
|
||||
ansi.InitPlain()
|
||||
writer = &color.PlainWriter{
|
||||
Ansi: ansi,
|
||||
}
|
||||
} else {
|
||||
ansi.Init(env.Shell(), env.GOOS())
|
||||
writerColors := cfg.MakeColors()
|
||||
writer = &color.AnsiWriter{
|
||||
Ansi: ansi,
|
||||
|
|
Loading…
Reference in a new issue