From aa10dccf900b5f0bdad475663f5dfe70757ea29d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 12 Aug 2022 22:18:10 +0900 Subject: 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 --- src/ansi_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/ansi_test.go') 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))) -- cgit v1.2.3