mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
fix(ansi): restore previous override correctly
This commit is contained in:
parent
2c7e6b26a3
commit
bd3cd316c2
|
@ -488,12 +488,15 @@ func (w *Writer) endColorOverride(position int) int {
|
|||
// make sure to reset the colors if needed
|
||||
position += len([]rune(resetStyle.AnchorEnd)) - 1
|
||||
|
||||
// reset colors to previous when we have > 2 in stack
|
||||
// - first is always the starting colors used in Write()
|
||||
// - second is the first override
|
||||
// as soon as we have more than 2, we can pop the last one
|
||||
// do not restore colors at the end of the string, we print it anyways
|
||||
if position == len(w.runes)-1 {
|
||||
return position
|
||||
}
|
||||
|
||||
// reset colors to previous when we have >= 2 in stack
|
||||
// as soon as we have more than 1, we can pop the last one
|
||||
// and print the previous override as it wasn't ended yet
|
||||
if w.current.Len() >= 3 {
|
||||
if w.current.Len() >= 2 {
|
||||
fg := w.current.Foreground()
|
||||
bg := w.current.Background()
|
||||
|
||||
|
@ -515,11 +518,6 @@ func (w *Writer) endColorOverride(position int) int {
|
|||
return position
|
||||
}
|
||||
|
||||
// do not restore colors at the end of the string, we print it anyways
|
||||
if position == len(w.runes)-1 {
|
||||
return position
|
||||
}
|
||||
|
||||
if w.transparent {
|
||||
w.writeEscapedAnsiString(transparentEnd)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func TestWriteANSIColors(t *testing.T) {
|
|||
{
|
||||
Case: "Bold with color override",
|
||||
Input: "<b><#ffffff>test</></b>",
|
||||
Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[49m\x1b[30m\x1b[22m\x1b[0m",
|
||||
Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[30m\x1b[22m\x1b[0m",
|
||||
Colors: &Colors{Foreground: "black", Background: ParentBackground},
|
||||
},
|
||||
{
|
||||
|
@ -41,7 +41,6 @@ func TestWriteANSIColors(t *testing.T) {
|
|||
Expected: "\x1b[38;2;255;255;255m\x1b[1mtest\x1b[22m\x1b[0m",
|
||||
Colors: &Colors{Foreground: "black", Background: ParentBackground},
|
||||
},
|
||||
|
||||
{
|
||||
Case: "Double override",
|
||||
Input: "<#ffffff>jan</>@<#ffffff>Jans-MBP</>",
|
||||
|
|
Loading…
Reference in a new issue