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:
Kovid Goyal
2017-09-09 10:25:03 +05:30
parent 382daacb73
commit bc97cfa024
7 changed files with 79 additions and 60 deletions

View File

@@ -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