mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
6cc4160ddf
commit
1b32fa0f9a
|
@ -62,6 +62,14 @@ func (c AnsiColor) IsTransparent() bool {
|
||||||
return c == transparentAnsiColor
|
return c == transparentAnsiColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c AnsiColor) ToForeground() AnsiColor {
|
||||||
|
colorString := string(c)
|
||||||
|
if strings.HasPrefix(colorString, "38;") {
|
||||||
|
return AnsiColor(strings.Replace(colorString, "38;", "48;", 1))
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Transparent implies a transparent color
|
// Transparent implies a transparent color
|
||||||
Transparent = "transparent"
|
Transparent = "transparent"
|
||||||
|
@ -111,8 +119,8 @@ func (a *AnsiWriter) writeColoredText(background, foreground AnsiColor, text str
|
||||||
foreground = a.getAnsiFromColorString("white", false)
|
foreground = a.getAnsiFromColorString("white", false)
|
||||||
}
|
}
|
||||||
if foreground.IsTransparent() && !background.IsEmpty() && len(a.TerminalBackground) != 0 {
|
if foreground.IsTransparent() && !background.IsEmpty() && len(a.TerminalBackground) != 0 {
|
||||||
fgAnsiColor := a.getAnsiFromColorString(a.TerminalBackground, false)
|
bgAnsiColor := a.getAnsiFromColorString(a.TerminalBackground, false)
|
||||||
coloredText := fmt.Sprintf(a.Ansi.colorFull, background, fgAnsiColor, text)
|
coloredText := fmt.Sprintf(a.Ansi.colorFull, background.ToForeground(), bgAnsiColor, text)
|
||||||
a.builder.WriteString(coloredText)
|
a.builder.WriteString(coloredText)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ func TestWriteANSIColors(t *testing.T) {
|
||||||
{
|
{
|
||||||
Case: "Transparent foreground, terminal background set",
|
Case: "Transparent foreground, terminal background set",
|
||||||
Input: "test",
|
Input: "test",
|
||||||
Expected: "\x1b[38;2;255;87;51m\x1b[38;2;33;47;60mtest\x1b[0m",
|
Expected: "\x1b[48;2;255;87;51m\x1b[38;2;33;47;60mtest\x1b[0m",
|
||||||
Colors: &Color{Foreground: Transparent, Background: "#FF5733"},
|
Colors: &Color{Foreground: Transparent, Background: "#FF5733"},
|
||||||
TerminalBackground: "#212F3C",
|
TerminalBackground: "#212F3C",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue