diff --git a/tools/wcswidth/escape-code-parser.go b/tools/wcswidth/escape-code-parser.go index 6786d6d9e..7cd786831 100644 --- a/tools/wcswidth/escape-code-parser.go +++ b/tools/wcswidth/escape-code-parser.go @@ -119,7 +119,7 @@ func (self *EscapeCodeParser) write_ch(ch byte) { } func csi_type(ch byte) csi_char_type { - if 0x30 <= ch && ch <= 0x3f { + if (0x30 <= ch && ch <= 0x3f) || ch == '-' { return parameter_csi_char } if 0x40 <= ch && ch <= 0x7E { diff --git a/tools/wcswidth/escape-code-parser_test.go b/tools/wcswidth/escape-code-parser_test.go index e2e858f85..ba8a787f9 100644 --- a/tools/wcswidth/escape-code-parser_test.go +++ b/tools/wcswidth/escape-code-parser_test.go @@ -46,6 +46,7 @@ func TestEscapeCodeParsing(t *testing.T) { } test("\x1b[31m\xc2\x9bm", "CSI: 31m\nCSI: m") + test("\x1b[-31m\xc2\x9bm", "CSI: -31m\nCSI: m") test("ab\nc", "CH: a\nCH: b\nCH: \n\nCH: c") test("a\x1b[200m\x1b[mb\x1b[5:3;2;4~", "CH: a\nCSI: 200m\nCSI: m\nCH: b\nCSI: 5:3;2;4~") test("\x1b[200~a\x1b[201m\x1b[201~\x1b[x", "CH: a\nCH: \x1b\nCH: [\nCH: 2\nCH: 0\nCH: 1\nCH: m\nCSI: x")