mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
parent
6cc4160ddf
commit
1b32fa0f9a
|
@ -62,6 +62,14 @@ func (c AnsiColor) IsTransparent() bool {
|
|||
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 (
|
||||
// Transparent implies a transparent color
|
||||
Transparent = "transparent"
|
||||
|
@ -111,8 +119,8 @@ func (a *AnsiWriter) writeColoredText(background, foreground AnsiColor, text str
|
|||
foreground = a.getAnsiFromColorString("white", false)
|
||||
}
|
||||
if foreground.IsTransparent() && !background.IsEmpty() && len(a.TerminalBackground) != 0 {
|
||||
fgAnsiColor := a.getAnsiFromColorString(a.TerminalBackground, false)
|
||||
coloredText := fmt.Sprintf(a.Ansi.colorFull, background, fgAnsiColor, text)
|
||||
bgAnsiColor := a.getAnsiFromColorString(a.TerminalBackground, false)
|
||||
coloredText := fmt.Sprintf(a.Ansi.colorFull, background.ToForeground(), bgAnsiColor, text)
|
||||
a.builder.WriteString(coloredText)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ func TestWriteANSIColors(t *testing.T) {
|
|||
{
|
||||
Case: "Transparent foreground, terminal background set",
|
||||
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"},
|
||||
TerminalBackground: "#212F3C",
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue