diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2022-08-12 22:18:10 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2022-08-13 22:30:50 +0900 |
| commit | aa10dccf900b5f0bdad475663f5dfe70757ea29d (patch) | |
| tree | 08fe0b2e6273792362de6ce897f5b5eef4cb993d /src/ansi_test.go | |
| parent | f4fd53211a9e3964818c2069aeff5464a679079f (diff) | |
| download | fzf-aa10dccf900b5f0bdad475663f5dfe70757ea29d.tar.gz | |
Support colon delimiter in ANSI escape sequences
# Both should work
printf "\e[38;5;208mOption 1\e[m\nOption 2" | fzf --ansi
printf "\e[38:5:208mOption 1\e[m\nOption 2" | fzf --ansi
This change makes ANSI parsing slightly slower.
cpu: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Before:
BenchmarkNextAnsiEscapeSequence-12 992.22 MB/s
BenchmarkExtractColor-12 174.35 MB/s
After:
BenchmarkNextAnsiEscapeSequence-12 925.05 MB/s
BenchmarkExtractColor-12 163.33 MB/s
Fix #2913
Diffstat (limited to 'src/ansi_test.go')
| -rw-r--r-- | src/ansi_test.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/ansi_test.go b/src/ansi_test.go index 781c0a10..657cf4e0 100644 --- a/src/ansi_test.go +++ b/src/ansi_test.go @@ -358,6 +358,7 @@ func TestAnsiCodeStringConversion(t *testing.T) { assert("\x1b[31m", &ansiState{fg: 4, bg: 4, lbg: -1}, "\x1b[31;44m") assert("\x1b[1;2;31m", &ansiState{fg: 2, bg: -1, attr: tui.Reverse, lbg: -1}, "\x1b[1;2;7;31;49m") assert("\x1b[38;5;100;48;5;200m", nil, "\x1b[38;5;100;48;5;200m") + assert("\x1b[38:5:100:48:5:200m", nil, "\x1b[38;5;100;48;5;200m") assert("\x1b[48;5;100;38;5;200m", nil, "\x1b[38;5;200;48;5;100m") assert("\x1b[48;5;100;38;2;10;20;30;1m", nil, "\x1b[1;38;2;10;20;30;48;5;100m") assert("\x1b[48;5;100;38;2;10;20;30;7m", @@ -377,7 +378,7 @@ func TestParseAnsiCode(t *testing.T) { {"-2", "", -1}, } for _, x := range tests { - n, s := parseAnsiCode(x.In) + n, _, s := parseAnsiCode(x.In, 0) if n != x.N || s != x.Exp { t.Fatalf("%q: got: (%d %q) want: (%d %q)", x.In, n, s, x.N, x.Exp) } @@ -385,9 +386,9 @@ func TestParseAnsiCode(t *testing.T) { } // kernel/bpf/preload/iterators/README -const ansiBenchmarkString = "\x1b[38;5;81m\x1b[01;31m\x1b[Kkernel/\x1b[0m\x1b[38;5;81mbpf/" + - "\x1b[0m\x1b[38;5;81mpreload/\x1b[0m\x1b[38;5;81miterators/" + - "\x1b[0m\x1b[38;5;149mMakefile\x1b[m\x1b[K\x1b[0m" +const ansiBenchmarkString = "\x1b[38;5;81m\x1b[01;31m\x1b[Kkernel/\x1b[0m\x1b[38:5:81mbpf/" + + "\x1b[0m\x1b[38:5:81mpreload/\x1b[0m\x1b[38;5;81miterators/" + + "\x1b[0m\x1b[38:5:149mMakefile\x1b[m\x1b[K\x1b[0m" func BenchmarkNextAnsiEscapeSequence(b *testing.B) { b.SetBytes(int64(len(ansiBenchmarkString))) |
