From 56cfc7df3bf426e36bb22a53d47b874e2df51462 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Nov 2016 08:50:55 +0530 Subject: [PATCH] Handle leading zeroes in CSI codes --- kitty/parser.c | 9 ++++++++- kitty_tests/parser.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kitty/parser.c b/kitty/parser.c index 1bb465e5a..178f5e903 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -15,9 +15,16 @@ static unsigned int pow10[10] = { static inline unsigned int utoi(uint32_t *buf, unsigned int sz) { unsigned int ans = 0; + uint32_t *p = buf; + // Ignore leading zeros + while(sz > 0) { + printf("*p=%c\n", *p); + if (*p == '0') { p++; sz--; } + else break; + } if (sz < sizeof(pow10)/sizeof(pow10[10])) { for (int i = sz-1, j=0; i >=0; i--, j++) { - ans += (buf[i] - '0') * pow10[j]; + ans += (p[i] - '0') * pow10[j]; } } return ans; diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 923135f7d..f4923b6f9 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -85,6 +85,7 @@ class TestParser(BaseTest): pb('\033[4H', ('screen_cursor_position', 4, 1)) pb('\033[3;2H', ('screen_cursor_position', 3, 2)) pb('\033[3;2;H', ('screen_cursor_position', 3, 2)) + pb('\033[00000000003;0000000000000002H', ('screen_cursor_position', 3, 2)) self.ae(s.cursor.x, 1), self.ae(s.cursor.y, 2) pb('\033[J', ('screen_erase_in_display', 0, 0)) pb('\033[?J', ('screen_erase_in_display', 0, 1))