Skip to content

Commit

Permalink
fix(ansi): allow usage of < and > in text with overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jan 26, 2024
1 parent 4fb18aa commit 011a4ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ansi/ansi_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/ansi/ansi_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 011a4ab

Please sign in to comment.