Implement the fast draw path for single width characters

This commit is contained in:
Kovid Goyal
2016-10-18 11:04:30 +05:30
parent 63d228f21b
commit 355bfce189
6 changed files with 232 additions and 44 deletions

View File

@@ -2,9 +2,32 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from collections import defaultdict
from unittest import TestCase
from kitty.screen import Screen
from kitty.tracker import ChangeTracker
from kitty.config import defaults
class BaseTest(TestCase):
ae = TestCase.assertEqual
def create_screen(self, cols=5, lines=5, history_size=5):
t = ChangeTracker()
opts = defaults._replace(scrollback_lines=history_size)
s = Screen(opts, t, columns=cols, lines=lines)
return s, t
def assertChanges(self, t, ignore='', **expected_changes):
actual_changes = t.consolidate_changes()
ignore = frozenset(ignore.split())
for k, v in actual_changes.items():
if isinstance(v, defaultdict):
v = dict(v)
if k not in ignore:
if k in expected_changes:
self.ae(expected_changes[k], v)
else:
self.assertFalse(v)

53
kitty_tests/screen.py Normal file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from . import BaseTest
from kitty.screen import mo
class TestScreen(BaseTest):
def test_draw_fast(self):
# Test in line-wrap, non-insert mode
s, t = self.create_screen()
s.draw(b'a' * 5)
self.ae(str(s.linebuf[0]), 'a' * 5)
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'b' * 7)
self.assertTrue(s.linebuf[1].continued)
self.assertTrue(s.linebuf[2].continued)
self.ae(str(s.linebuf[0]), 'a' * 5)
self.ae(str(s.linebuf[1]), 'b' * 5)
self.ae(str(s.linebuf[2]), 'b' * 2 + ' ' * 3)
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
self.assertChanges(t, ignore='cursor', cells={1: ((0, 4),), 2: ((0, 1),)})
s.draw(b'c' * 15)
self.ae(str(s.linebuf[0]), 'b' * 5)
self.ae(str(s.linebuf[1]), 'bbccc')
# Now test without line-wrap
s.reset(), t.reset()
s.reset_mode(mo.DECAWM)
s.draw(b'0123456789')
self.ae(str(s.linebuf[0]), '56789')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((0, 4),)})
s.draw(b'ab')
self.ae(str(s.linebuf[0]), '567ab')
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
self.assertChanges(t, ignore='cursor', cells={0: ((3, 4),)})
# Now test in insert mode
s.reset(), t.reset()
s.set_mode(mo.IRM)
s.draw(b'12345' * 5)
s.cursor_back(5)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
t.reset()
s.draw(b'ab')
self.ae(str(s.linebuf[4]), 'ab123')
self.ae((s.cursor.x, s.cursor.y), (2, 4))
self.assertChanges(t, ignore='cursor', cells={4: ((0, 4),)})