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() defer env.Close()
cfg := engine.LoadConfig(env) cfg := engine.LoadConfig(env)
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
writerColors := cfg.MakeColors() writerColors := cfg.MakeColors()
writer := &color.AnsiWriter{ writer := &color.AnsiWriter{
Ansi: ansi, Ansi: ansi,

View file

@ -34,7 +34,7 @@ var debugCmd = &cobra.Command{
defer env.Close() defer env.Close()
cfg := engine.LoadConfig(env) cfg := engine.LoadConfig(env)
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain(env.GOOS()) ansi.InitPlain()
writerColors := cfg.MakeColors() writerColors := cfg.MakeColors()
writer := &color.AnsiWriter{ writer := &color.AnsiWriter{
Ansi: ansi, Ansi: ansi,

View file

@ -148,8 +148,8 @@ func (a *Ansi) Init(shellName, goos string) {
} }
} }
func (a *Ansi) InitPlain(goos string) { func (a *Ansi) InitPlain() {
a.Init(shell.PLAIN, goos) a.Init(shell.PLAIN, "")
} }
func (a *Ansi) GenerateHyperlink(text string) string { func (a *Ansi) GenerateHyperlink(text string) string {

View file

@ -96,7 +96,7 @@ func TestFormatText(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
a := Ansi{} a := Ansi{}
a.InitPlain("") a.InitPlain()
formattedText := a.formatText(tc.Text) formattedText := a.formatText(tc.Text)
assert.Equal(t, tc.Expected, formattedText, tc.Case) assert.Equal(t, tc.Expected, formattedText, tc.Case)
} }

View file

@ -62,7 +62,7 @@ func TestGetTitle(t *testing.T) {
Folder: "vagrant", Folder: "vagrant",
}) })
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
ct := &Title{ ct := &Title{
Env: env, Env: env,
Ansi: ansi, Ansi: ansi,
@ -117,7 +117,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
HostName: "", HostName: "",
}) })
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
ct := &Title{ ct := &Title{
Env: env, Env: env,
Ansi: ansi, 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) { func (b *Block) InitPlain(env platform.Environment, config *Config) {
b.ansi = &color.Ansi{} b.ansi = &color.Ansi{}
b.ansi.InitPlain(b.env.GOOS()) b.ansi.InitPlain()
b.writer = &color.AnsiWriter{ b.writer = &color.AnsiWriter{
Ansi: b.ansi, Ansi: b.ansi,
TerminalBackground: shell.ConsoleBackgroundColor(env, config.TerminalBackground), TerminalBackground: shell.ConsoleBackgroundColor(env, config.TerminalBackground),

View file

@ -211,7 +211,7 @@ func (e *Engine) renderBlock(block *Block) {
ansi := e.Ansi ansi := e.Ansi
if e.Env.Shell() == shell.BASH { if e.Env.Shell() == shell.BASH {
ansi = &color.Ansi{} ansi = &color.Ansi{}
ansi.InitPlain(e.Env.GOOS()) ansi.InitPlain()
} }
prompt := ansi.CarriageForward() prompt := ansi.CarriageForward()
prompt += ansi.GetCursorForRightWrite(length, block.HorizontalOffset) 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 // 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 // see https://github.com/jandedobbeleer/oh-my-posh/pull/2398
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain(e.Env.GOOS()) ansi.InitPlain()
prompt := ansi.SaveCursorPosition() prompt := ansi.SaveCursorPosition()
prompt += ansi.CarriageForward() prompt += ansi.CarriageForward()
prompt += ansi.GetCursorForRightWrite(e.rpromptLength, 0) prompt += ansi.GetCursorForRightWrite(e.rpromptLength, 0)

View file

@ -72,7 +72,7 @@ func TestPrintPWD(t *testing.T) {
Shell: "shell", Shell: "shell",
}) })
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
engine := &Engine{ engine := &Engine{
Env: env, Env: env,
Config: &Config{ Config: &Config{
@ -102,7 +102,7 @@ func engineRender() {
defer testClearDefaultConfig() defer testClearDefaultConfig()
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
writerColors := cfg.MakeColors() writerColors := cfg.MakeColors()
writer := &color.AnsiWriter{ writer := &color.AnsiWriter{
Ansi: ansi, Ansi: ansi,

View file

@ -33,7 +33,7 @@ func runImageTest(config, content string) (string, error) {
} }
defer os.Remove(file.Name()) defer os.Remove(file.Name())
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.InitPlain("") ansi.InitPlain()
image := &ImageRenderer{ image := &ImageRenderer{
AnsiString: content, AnsiString: content,
Ansi: ansi, Ansi: ansi,

View file

@ -18,15 +18,15 @@ func New(flags *platform.Flags) *Engine {
env.Init() env.Init()
cfg := LoadConfig(env) cfg := LoadConfig(env)
ansi := &color.Ansi{} ansi := &color.Ansi{}
ansi.Init(env.Shell(), env.GOOS())
var writer color.Writer var writer color.Writer
if flags.Plain { if flags.Plain {
ansi.InitPlain(env.GOOS()) ansi.InitPlain()
writer = &color.PlainWriter{ writer = &color.PlainWriter{
Ansi: ansi, Ansi: ansi,
} }
} else { } else {
ansi.Init(env.Shell(), env.GOOS())
writerColors := cfg.MakeColors() writerColors := cfg.MakeColors()
writer = &color.AnsiWriter{ writer = &color.AnsiWriter{
Ansi: ansi, Ansi: ansi,