Also parse negative numbers in CSI

This commit is contained in:
Kovid Goyal 2023-03-29 15:12:22 +05:30
parent aebfdaa69a
commit 05e10d8066
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 1 deletions

View File

@ -119,7 +119,7 @@ func (self *EscapeCodeParser) write_ch(ch byte) {
} }
func csi_type(ch byte) csi_char_type { func csi_type(ch byte) csi_char_type {
if 0x30 <= ch && ch <= 0x3f { if (0x30 <= ch && ch <= 0x3f) || ch == '-' {
return parameter_csi_char return parameter_csi_char
} }
if 0x40 <= ch && ch <= 0x7E { if 0x40 <= ch && ch <= 0x7E {

View File

@ -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("\x1b[-31m\xc2\x9bm", "CSI: -31m\nCSI: m")
test("ab\nc", "CH: a\nCH: b\nCH: \n\nCH: c") 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("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") 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")