fix(ansi): allow usage of < and > in text with overrides

This commit is contained in:
Jan De Dobbeleer 2024-01-26 17:07:44 +01:00 committed by Jan De Dobbeleer
parent 4fb18aaac7
commit 011a4ab8f5
2 changed files with 7 additions and 1 deletions

View file

@ -54,7 +54,7 @@ const (
// Foreground takes the current segment's foreground color
Foreground = "foreground"
AnchorRegex = `^(?P<ANCHOR><(?P<FG>[^,>]+)?,?(?P<BG>[^>]+)?>)`
AnchorRegex = `^(?P<ANCHOR><(?P<FG>[^,<>]+)?,?(?P<BG>[^<>]+)?>)`
colorise = "\x1b[%sm"
transparent = "\x1b[0m\x1b[%s;49m\x1b[7m"
transparentEnd = "\x1b[27m"

View file

@ -206,6 +206,12 @@ func TestWriteANSIColors(t *testing.T) {
Expected: "\x1b[47m\x1b[30mhome\x1b[0m\x1b[37;49m\x1b[7m / \x1b[27m\x1b[47m\x1b[30mcode\x1b[0m\x1b[37;49m\x1b[7m / \x1b[27m\x1b[47m\x1b[30msrc \x1b[0m",
Colors: &Colors{Foreground: "black", Background: "white"},
},
{
Case: "Larger than and less than symbols",
Input: "<red><</><orange>></><yellow><</>",
Expected: "\x1b[47m\x1b[31m<\x1b[30m>\x1b[33m<\x1b[0m",
Colors: &Colors{Foreground: "black", Background: "white"},
},
}
for _, tc := range cases {