mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-09 13:45:26 +02:00
Use a null to represent a blank rather than a space
This has performance benefits when clearing (can use a single memset). Also allows detecting trailing whitespace on lines correctly.
This commit is contained in:
@@ -34,7 +34,7 @@ class TestDataTypes(BaseTest):
|
||||
new.copy_old(old)
|
||||
self.ae(new.line(0), old.line(1))
|
||||
new.clear()
|
||||
self.ae(str(new.line(0)), ' ' * new.xnum)
|
||||
self.ae(str(new.line(0)), '')
|
||||
old.set_attribute(REVERSE, False)
|
||||
for y in range(old.ynum):
|
||||
for x in range(old.xnum):
|
||||
@@ -140,22 +140,23 @@ class TestDataTypes(BaseTest):
|
||||
lb = LineBuf(2, 3)
|
||||
for y in range(lb.ynum):
|
||||
line = lb.line(y)
|
||||
self.ae(str(line), ' ' * lb.xnum)
|
||||
self.ae(str(line), '')
|
||||
for x in range(lb.xnum):
|
||||
self.ae(line[x], ' ')
|
||||
self.ae(line[x], '\0')
|
||||
with self.assertRaises(IndexError):
|
||||
lb.line(lb.ynum)
|
||||
with self.assertRaises(IndexError):
|
||||
lb.line(0)[lb.xnum]
|
||||
l = lb.line(0)
|
||||
l.set_text(' ', 0, len(' '), C())
|
||||
l.add_combining_char(0, '1')
|
||||
self.ae(l[0], ' 1')
|
||||
l.add_combining_char(0, '2')
|
||||
self.ae(l[0], ' 12')
|
||||
l.add_combining_char(0, '3')
|
||||
self.ae(l[0], ' 13')
|
||||
self.ae(l[1], ' ')
|
||||
self.ae(str(l), ' 13 ')
|
||||
self.ae(l[1], '\0')
|
||||
self.ae(str(l), ' 13')
|
||||
t = 'Testing with simple text'
|
||||
lb = LineBuf(2, len(t))
|
||||
l = lb.line(0)
|
||||
@@ -257,18 +258,21 @@ class TestDataTypes(BaseTest):
|
||||
def test_rewrap_wider(self):
|
||||
' New buffer wider '
|
||||
lb = create_lbuf('0123 ', '56789')
|
||||
lb2 = self.line_comparison_rewrap(lb, '0123 5', '6789 ', ' ' * 6)
|
||||
lb2 = self.line_comparison_rewrap(lb, '0123 5', '6789', '')
|
||||
self.assertContinued(lb2, False, True)
|
||||
|
||||
lb = create_lbuf('12', 'abc')
|
||||
lb2 = self.line_comparison_rewrap(lb, '12 ', 'abc ')
|
||||
lb2 = self.line_comparison_rewrap(lb, '12', 'abc')
|
||||
self.assertContinued(lb2, False, False)
|
||||
|
||||
def test_rewrap_narrower(self):
|
||||
' New buffer narrower '
|
||||
lb = create_lbuf('123 ', 'abcde')
|
||||
lb2 = self.line_comparison_rewrap(lb, '123', 'abc', 'de ')
|
||||
lb = create_lbuf('123', 'abcde')
|
||||
lb2 = self.line_comparison_rewrap(lb, '123', 'abc', 'de')
|
||||
self.assertContinued(lb2, False, False, True)
|
||||
lb = create_lbuf('123 ', 'abcde')
|
||||
lb2 = self.line_comparison_rewrap(lb, '123', ' a', 'bcd', 'e')
|
||||
self.assertContinued(lb2, False, True, True, True)
|
||||
|
||||
@skipIf('ANCIENT_WCWIDTH' in os.environ, 'wcwidth() is too old')
|
||||
def test_utils(self):
|
||||
|
||||
@@ -45,15 +45,15 @@ class TestParser(BaseTest):
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
|
||||
pb('12', '12')
|
||||
self.ae(str(s.line(0)), '12 ')
|
||||
self.ae(str(s.line(0)), '12')
|
||||
self.ae(s.cursor.x, 2)
|
||||
pb('3456', '3456')
|
||||
self.ae(str(s.line(0)), '12345')
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
self.ae(str(s.line(1)), '6')
|
||||
pb(b'\n123\n\r45', ('screen_linefeed',), '123', ('screen_linefeed',), ('screen_carriage_return',), '45')
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
self.ae(str(s.line(2)), ' 123 ')
|
||||
self.ae(str(s.line(3)), '45 ')
|
||||
self.ae(str(s.line(1)), '6')
|
||||
self.ae(str(s.line(2)), ' 123')
|
||||
self.ae(str(s.line(3)), '45')
|
||||
parse_bytes(s, b'\rabcde')
|
||||
self.ae(str(s.line(3)), 'abcde')
|
||||
pb('\rßxyz1', ('screen_carriage_return',), 'ßxyz1')
|
||||
@@ -65,11 +65,11 @@ class TestParser(BaseTest):
|
||||
s = self.create_screen()
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
pb('12\033Da', '12', ('screen_index',), 'a')
|
||||
self.ae(str(s.line(0)), '12 ')
|
||||
self.ae(str(s.line(1)), ' a ')
|
||||
self.ae(str(s.line(0)), '12')
|
||||
self.ae(str(s.line(1)), ' a')
|
||||
pb('\033x', ('Unknown char after ESC: 0x%x' % ord('x'),))
|
||||
pb('\033c123', ('screen_reset', ), '123')
|
||||
self.ae(str(s.line(0)), '123 ')
|
||||
self.ae(str(s.line(0)), '123')
|
||||
|
||||
def test_charsets(self):
|
||||
s = self.create_screen()
|
||||
@@ -79,14 +79,14 @@ class TestParser(BaseTest):
|
||||
s = self.create_screen()
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
pb('\033)0\x0e/_', ('screen_designate_charset', 1, ord('0')), ('screen_change_charset', 1), '/_')
|
||||
self.ae(str(s.line(0)), '/\xa0 ')
|
||||
self.ae(str(s.line(0)), '/\xa0')
|
||||
self.assertTrue(s.callbacks.iutf8)
|
||||
pb('\033%@_', ('screen_use_latin1', 1), '_')
|
||||
self.assertFalse(s.callbacks.iutf8)
|
||||
s = self.create_screen()
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
pb('\033(0/_', ('screen_designate_charset', 0, ord('0')), '/_')
|
||||
self.ae(str(s.line(0)), '/\xa0 ')
|
||||
self.ae(str(s.line(0)), '/\xa0')
|
||||
|
||||
def test_csi_codes(self):
|
||||
s = self.create_screen()
|
||||
|
||||
@@ -23,7 +23,7 @@ class TestScreen(BaseTest):
|
||||
self.assertTrue(s.linebuf.is_continued(2))
|
||||
self.ae(str(s.line(0)), 'a' * 5)
|
||||
self.ae(str(s.line(1)), 'b' * 5)
|
||||
self.ae(str(s.line(2)), 'b' * 2 + ' ' * 3)
|
||||
self.ae(str(s.line(2)), 'b' * 2)
|
||||
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
|
||||
s.draw('c' * 15)
|
||||
self.ae(str(s.line(0)), 'b' * 5)
|
||||
@@ -60,17 +60,17 @@ class TestScreen(BaseTest):
|
||||
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
||||
s.draw('ニチハ')
|
||||
self.ae(str(s.line(0)), 'ココx')
|
||||
self.ae(str(s.line(1)), 'ニチ ')
|
||||
self.ae(str(s.line(2)), 'ハ ')
|
||||
self.ae(str(s.line(1)), 'ニチ')
|
||||
self.ae(str(s.line(2)), 'ハ')
|
||||
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
|
||||
s.draw('Ƶ̧\u0308')
|
||||
self.ae(str(s.line(2)), 'ハƵ̧\u0308 ')
|
||||
self.ae(str(s.line(2)), 'ハƵ̧\u0308')
|
||||
self.ae(s.cursor.x, 3), self.ae(s.cursor.y, 2)
|
||||
s.draw('xy'), s.draw('\u0306')
|
||||
self.ae(str(s.line(2)), 'ハƵ̧\u0308xy\u0306')
|
||||
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 2)
|
||||
s.draw('c' * 15)
|
||||
self.ae(str(s.line(0)), 'ニチ ')
|
||||
self.ae(str(s.line(0)), 'ニチ')
|
||||
|
||||
# Now test without line-wrap
|
||||
s.reset(), s.reset_dirty()
|
||||
@@ -111,12 +111,12 @@ class TestScreen(BaseTest):
|
||||
self.assertTrue(s.line(0).cursor_from(1).bold)
|
||||
s.cursor_back(1)
|
||||
s.insert_characters(20)
|
||||
self.ae(str(s.line(0)), ' ')
|
||||
self.ae(str(s.line(0)), '')
|
||||
s.draw('xココ')
|
||||
s.cursor_back(5)
|
||||
s.reset_dirty()
|
||||
s.insert_characters(1)
|
||||
self.ae(str(s.line(0)), ' xコ ')
|
||||
self.ae(str(s.line(0)), ' xコ')
|
||||
c = Cursor()
|
||||
c.italic = True
|
||||
s.line(0).apply_cursor(c, 0, 5)
|
||||
@@ -126,7 +126,7 @@ class TestScreen(BaseTest):
|
||||
|
||||
init()
|
||||
s.delete_characters(2)
|
||||
self.ae(str(s.line(0)), 'ade ')
|
||||
self.ae(str(s.line(0)), 'ade')
|
||||
self.assertTrue(s.line(0).cursor_from(4).bold)
|
||||
self.assertFalse(s.line(0).cursor_from(2).bold)
|
||||
|
||||
@@ -136,11 +136,11 @@ class TestScreen(BaseTest):
|
||||
self.assertTrue(s.line(0).cursor_from(1).bold)
|
||||
self.assertFalse(s.line(0).cursor_from(4).bold)
|
||||
s.erase_characters(20)
|
||||
self.ae(str(s.line(0)), 'a ')
|
||||
self.ae(str(s.line(0)), 'a')
|
||||
|
||||
init()
|
||||
s.erase_in_line()
|
||||
self.ae(str(s.line(0)), 'a ')
|
||||
self.ae(str(s.line(0)), 'a')
|
||||
self.assertTrue(s.line(0).cursor_from(1).bold)
|
||||
self.assertFalse(s.line(0).cursor_from(0).bold)
|
||||
init()
|
||||
@@ -148,7 +148,7 @@ class TestScreen(BaseTest):
|
||||
self.ae(str(s.line(0)), ' cde')
|
||||
init()
|
||||
s.erase_in_line(2)
|
||||
self.ae(str(s.line(0)), ' ')
|
||||
self.ae(str(s.line(0)), '')
|
||||
init()
|
||||
s.erase_in_line(2, True)
|
||||
self.ae((False, False, False, False, False), tuple(map(lambda i: s.line(0).cursor_from(i).bold, range(5))))
|
||||
@@ -168,19 +168,19 @@ class TestScreen(BaseTest):
|
||||
|
||||
init()
|
||||
s.erase_in_display()
|
||||
self.ae(all_lines(s), ('12345', '12 ', ' ', ' ', ' '))
|
||||
self.ae(all_lines(s), ('12345', '12', '', '', ''))
|
||||
|
||||
init()
|
||||
s.erase_in_display(1)
|
||||
self.ae(all_lines(s), (' ', ' 45', '12345', '12345', '12345'))
|
||||
self.ae(all_lines(s), ('', ' 45', '12345', '12345', '12345'))
|
||||
|
||||
init()
|
||||
s.erase_in_display(2)
|
||||
self.ae(all_lines(s), (' ', ' ', ' ', ' ', ' '))
|
||||
self.ae(all_lines(s), ('', '', '', '', ''))
|
||||
self.assertTrue(s.line(0).cursor_from(1).bold)
|
||||
init()
|
||||
s.erase_in_display(2, True)
|
||||
self.ae(all_lines(s), (' ', ' ', ' ', ' ', ' '))
|
||||
self.ae(all_lines(s), ('', '', '', '', ''))
|
||||
self.assertFalse(s.line(0).cursor_from(1).bold)
|
||||
|
||||
def test_cursor_movement(self):
|
||||
@@ -203,13 +203,13 @@ class TestScreen(BaseTest):
|
||||
s = self.create_screen()
|
||||
s.draw('12345' * 5)
|
||||
s.index()
|
||||
self.ae(str(s.line(4)), ' ' * 5)
|
||||
self.ae(str(s.line(4)), '')
|
||||
for i in range(4):
|
||||
self.ae(str(s.line(i)), '12345')
|
||||
s.draw('12345' * 5)
|
||||
s.cursor_up(5)
|
||||
s.reverse_index()
|
||||
self.ae(str(s.line(0)), ' ' * 5)
|
||||
self.ae(str(s.line(0)), '')
|
||||
for i in range(1, 5):
|
||||
self.ae(str(s.line(i)), '12345')
|
||||
|
||||
@@ -219,7 +219,7 @@ class TestScreen(BaseTest):
|
||||
s.resize(3, 10)
|
||||
self.ae(str(s.line(0)), '0'*5 + '1'*5)
|
||||
self.ae(str(s.line(1)), '2'*5 + '3'*5)
|
||||
self.ae(str(s.line(2)), '4'*5 + ' '*5)
|
||||
self.ae(str(s.line(2)), '4'*5)
|
||||
s.resize(5, 1)
|
||||
self.ae(str(s.line(0)), '4')
|
||||
hb = s.historybuf
|
||||
@@ -229,8 +229,8 @@ class TestScreen(BaseTest):
|
||||
s.draw(''.join([str(i) * s.columns for i in range(s.lines*2)]))
|
||||
self.ae(str(s.line(4)), '9'*5)
|
||||
s.resize(5, 2)
|
||||
self.ae(str(s.line(3)), '9 ')
|
||||
self.ae(str(s.line(4)), ' ')
|
||||
self.ae(str(s.line(3)), '9')
|
||||
self.ae(str(s.line(4)), '')
|
||||
|
||||
def test_tab_stops(self):
|
||||
# Taken from vttest/main.c
|
||||
|
||||
Reference in New Issue
Block a user