From c421d3bb590ae4a91c65755d79dfb8af2af6f005 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 16 Sep 2018 04:34:41 +0900 Subject: [PATCH] line_as_ansi: don't reset SGR at start of line less does not carry the mode over from the previous line anyway, let's save a few bytes for every line --- kitty/line.c | 1 - kitty_tests/datatypes.py | 10 +++++----- kitty_tests/screen.py | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/kitty/line.c b/kitty/line.c index 4e6775359..7ae5cf7af 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -235,7 +235,6 @@ line_as_ansi(Line *self, Py_UCS4 *buf, index_type buflen) { if (limit == 0) return 0; char_type previous_width = 0; - WRITE_SGR("0"); Cursor c1 = {{0}}, c2 = {{0}}; Cursor *cursor = &c1, *prev_cursor = &c2; char_type prev_attrs = 0; diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index e9e41c3b1..fa33f77a8 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -447,10 +447,10 @@ class TestDataTypes(BaseTest): def test_ansi_repr(self): lb = filled_line_buf() l0 = lb.line(0) - self.ae(l0.as_ansi(), '\x1b[0m00000') + self.ae(l0.as_ansi(), '00000') a = [] lb.as_ansi(a.append) - self.ae(a, ['\x1b[0m' + str(lb.line(i)) + '\n' for i in range(lb.ynum)]) + self.ae(a, [str(lb.line(i)) + '\n' for i in range(lb.ynum)]) l2 = lb.line(0) c = C() c.bold = c.italic = c.reverse = c.strikethrough = c.dim = True @@ -458,15 +458,15 @@ class TestDataTypes(BaseTest): c.bg = (1 << 24) | (2 << 16) | (3 << 8) | 2 c.decoration_fg = (5 << 8) | 1 l2.set_text('1', 0, 1, c) - self.ae(l2.as_ansi(), '\x1b[0m\x1b[1;2;3;7;9;34;48:2:1:2:3;58:5:5m' '1' + self.ae(l2.as_ansi(), '\x1b[1;2;3;7;9;34;48:2:1:2:3;58:5:5m' '1' '\x1b[22;23;27;29;39;49;59m' '0000') lb = filled_line_buf() for i in range(lb.ynum): lb.set_continued(i, True) a = [] lb.as_ansi(a.append) - self.ae(a, ['\x1b[0m' + str(lb.line(i)) for i in range(lb.ynum)]) + self.ae(a, [str(lb.line(i)) for i in range(lb.ynum)]) hb = filled_history_buf(5, 5) a = [] hb.as_ansi(a.append) - self.ae(a, ['\x1b[0m' + str(hb.line(i)) + '\n' for i in range(hb.count - 1, -1, -1)]) + self.ae(a, [str(hb.line(i)) + '\n' for i in range(hb.count - 1, -1, -1)]) diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 7ede2ef8d..9b31da3d0 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -441,4 +441,4 @@ class TestScreen(BaseTest): return ''.join(d) self.ae(as_text(), 'ababababab\nc\n\n') - self.ae(as_text(True), '\x1b[0mababa\x1b[0mbabab\n\x1b[0mc\n\n') + self.ae(as_text(True), 'ababababab\nc\n\n')