refactor(ansi): do not allow plain GOOS override

This commit is contained in:
Jan De Dobbeleer 2023-01-02 19:16:51 +01:00 committed by Jan De Dobbeleer
parent ce7b7f1501
commit 77d5c9ed95
10 changed files with 15 additions and 15 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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 {

View file

@ -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)
}

View file

@ -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,

View file

@ -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),

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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,