2016-10-18 08:34:30 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# vim:fileencoding=utf-8
|
|
|
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
|
|
|
|
from . import BaseTest
|
|
|
|
|
2016-11-13 14:21:14 +03:00
|
|
|
from kitty.fast_data_types import DECAWM, IRM, Cursor
|
2016-10-18 08:34:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TestScreen(BaseTest):
|
|
|
|
|
2016-11-08 07:23:51 +03:00
|
|
|
def test_draw_fast(self):
|
2016-11-13 19:53:28 +03:00
|
|
|
s = self.create_screen()
|
2016-11-13 11:40:57 +03:00
|
|
|
|
2016-10-18 08:34:30 +03:00
|
|
|
# Test in line-wrap, non-insert mode
|
|
|
|
s.draw(b'a' * 5)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'a' * 5)
|
2016-10-18 08:34:30 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'b' * 7)
|
2016-11-08 07:23:51 +03:00
|
|
|
self.assertTrue(s.linebuf.is_continued(1))
|
|
|
|
self.assertTrue(s.linebuf.is_continued(2))
|
2016-10-20 21:35:50 +03:00
|
|
|
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)
|
2016-10-18 08:34:30 +03:00
|
|
|
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={1: ((0, 4),), 2: ((0, 1),)})
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'c' * 15)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'b' * 5)
|
|
|
|
self.ae(str(s.line(1)), 'bbccc')
|
2016-10-18 08:34:30 +03:00
|
|
|
|
|
|
|
# Now test without line-wrap
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset(), s.reset_dirty()
|
2016-11-13 11:40:57 +03:00
|
|
|
s.reset_mode(DECAWM)
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'0123456789')
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), '01239')
|
2016-10-18 08:34:30 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'ab')
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), '0123b')
|
2016-10-18 08:34:30 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((4, 4),)})
|
2016-10-18 08:34:30 +03:00
|
|
|
|
|
|
|
# Now test in insert mode
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset(), s.reset_dirty()
|
2016-11-13 11:40:57 +03:00
|
|
|
s.set_mode(IRM)
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'12345' * 5)
|
|
|
|
s.cursor_back(5)
|
|
|
|
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-18 08:34:30 +03:00
|
|
|
s.draw(b'ab')
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(4)), 'ab123')
|
2016-10-18 08:34:30 +03:00
|
|
|
self.ae((s.cursor.x, s.cursor.y), (2, 4))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={4: ((0, 4),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
|
2016-11-08 07:23:51 +03:00
|
|
|
def test_draw_char(self):
|
2016-10-18 18:00:18 +03:00
|
|
|
# Test in line-wrap, non-insert mode
|
2016-11-13 19:53:28 +03:00
|
|
|
s = self.create_screen()
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('ココx'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'ココx')
|
|
|
|
self.ae(tuple(map(s.line(0).width, range(5))), (2, 0, 2, 0, 1))
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('ニチハ'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'ココx')
|
|
|
|
self.ae(str(s.line(1)), 'ニチ ')
|
|
|
|
self.ae(str(s.line(2)), 'ハ ')
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={1: ((0, 3),), 2: ((0, 1),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 2), self.ae(s.cursor.y, 2)
|
|
|
|
s.draw('Ƶ̧\u0308'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(2)), 'ハƵ̧\u0308 ')
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 3), self.ae(s.cursor.y, 2)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={2: ((2, 2),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw(b'xy'), s.draw('\u0306'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(2)), 'ハƵ̧\u0308xy\u0306')
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 2)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={2: ((3, 4),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw(b'c' * 15)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'ニチ ')
|
2016-10-18 18:00:18 +03:00
|
|
|
|
|
|
|
# Now test without line-wrap
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset(), s.reset_dirty()
|
2016-11-13 11:40:57 +03:00
|
|
|
s.reset_mode(DECAWM)
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('0\u030612345\u03066789\u0306'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), '0\u03061239\u0306')
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('ab\u0306'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), '0\u0306123b\u0306')
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae(s.cursor.x, 5), self.ae(s.cursor.y, 0)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((4, 4),)})
|
2016-10-18 18:00:18 +03:00
|
|
|
|
|
|
|
# Now test in insert mode
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset(), s.reset_dirty()
|
2016-11-13 11:40:57 +03:00
|
|
|
s.set_mode(IRM)
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('1\u03062345'.encode('utf-8') * 5)
|
|
|
|
s.cursor_back(5)
|
|
|
|
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 4)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-18 18:00:18 +03:00
|
|
|
s.draw('a\u0306b'.encode('utf-8'))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(4)), 'a\u0306b1\u030623')
|
2016-10-18 18:00:18 +03:00
|
|
|
self.ae((s.cursor.x, s.cursor.y), (2, 4))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={4: ((0, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
|
2016-11-08 07:23:51 +03:00
|
|
|
def test_char_manipulation(self):
|
2016-11-13 19:53:28 +03:00
|
|
|
s = self.create_screen()
|
2016-10-19 08:55:55 +03:00
|
|
|
|
|
|
|
def init():
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset(), s.reset_dirty()
|
2016-10-19 08:55:55 +03:00
|
|
|
s.draw(b'abcde')
|
|
|
|
s.cursor.bold = True
|
|
|
|
s.cursor_back(4)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-19 08:55:55 +03:00
|
|
|
self.ae(s.cursor.x, 1)
|
|
|
|
|
|
|
|
init()
|
|
|
|
s.insert_characters(2)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'a bc')
|
|
|
|
self.assertTrue(s.line(0).cursor_from(1).bold)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((1, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
s.cursor_back(1)
|
|
|
|
s.insert_characters(20)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), ' ')
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
s.draw('xココ'.encode('utf-8'))
|
|
|
|
s.cursor_back(5)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-19 08:55:55 +03:00
|
|
|
s.insert_characters(1)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), ' xコ ')
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((0, 4),)})
|
2016-11-13 14:21:14 +03:00
|
|
|
c = Cursor()
|
2016-11-13 14:22:59 +03:00
|
|
|
c.italic = True
|
2016-11-13 14:21:14 +03:00
|
|
|
s.line(0).apply_cursor(c, 0, 5)
|
|
|
|
self.ae(s.line(0).width(2), 2)
|
2016-11-13 14:22:59 +03:00
|
|
|
self.assertTrue(s.line(0).cursor_from(2).italic)
|
|
|
|
self.assertFalse(s.line(0).cursor_from(2).bold)
|
2016-10-19 08:55:55 +03:00
|
|
|
|
|
|
|
init()
|
|
|
|
s.delete_characters(2)
|
2016-10-20 21:35:50 +03:00
|
|
|
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)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, ignore='cursor', cells={0: ((1, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
|
|
|
|
init()
|
|
|
|
s.erase_characters(2)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'a de')
|
|
|
|
self.assertTrue(s.line(0).cursor_from(1).bold)
|
|
|
|
self.assertFalse(s.line(0).cursor_from(4).bold)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, cells={0: ((1, 2),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
s.erase_characters(20)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), 'a ')
|
2016-10-19 08:55:55 +03:00
|
|
|
|
|
|
|
init()
|
|
|
|
s.erase_in_line()
|
2016-10-20 21:35:50 +03:00
|
|
|
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)
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, cells={0: ((1, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
init()
|
|
|
|
s.erase_in_line(1)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), ' cde')
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, cells={0: ((0, 1),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
init()
|
|
|
|
s.erase_in_line(2)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae(str(s.line(0)), ' ')
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, cells={0: ((0, 4),)})
|
2016-10-19 08:55:55 +03:00
|
|
|
init()
|
2016-11-13 14:21:14 +03:00
|
|
|
s.erase_in_line(2, True)
|
2016-10-20 21:35:50 +03:00
|
|
|
self.ae((False, False, False, False, False), tuple(map(lambda i: s.line(0).cursor_from(i).bold, range(5))))
|
2016-10-19 11:19:27 +03:00
|
|
|
|
2016-11-08 07:23:51 +03:00
|
|
|
def test_erase_in_screen(self):
|
2016-11-13 19:53:28 +03:00
|
|
|
s = self.create_screen()
|
2016-10-19 11:19:27 +03:00
|
|
|
|
|
|
|
def init():
|
|
|
|
s.reset()
|
|
|
|
s.draw(b'12345' * 5)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-19 11:19:27 +03:00
|
|
|
s.cursor.x, s.cursor.y = 2, 1
|
|
|
|
s.cursor.bold = True
|
|
|
|
|
2016-11-13 14:31:45 +03:00
|
|
|
def all_lines(s):
|
|
|
|
return tuple(str(s.line(i)) for i in range(s.lines))
|
|
|
|
|
2016-10-19 11:19:27 +03:00
|
|
|
init()
|
|
|
|
s.erase_in_display()
|
2016-11-13 14:31:45 +03:00
|
|
|
self.ae(all_lines(s), ('12345', '12 ', ' ', ' ', ' '))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, lines={2, 3, 4}, cells={1: ((2, 4),)})
|
2016-10-19 11:19:27 +03:00
|
|
|
|
|
|
|
init()
|
|
|
|
s.erase_in_display(1)
|
2016-11-13 14:31:45 +03:00
|
|
|
self.ae(all_lines(s), (' ', ' 45', '12345', '12345', '12345'))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, lines={0}, cells={1: ((0, 2),)})
|
2016-10-19 11:19:27 +03:00
|
|
|
|
|
|
|
init()
|
|
|
|
s.erase_in_display(2)
|
2016-11-13 14:31:45 +03:00
|
|
|
self.ae(all_lines(s), (' ', ' ', ' ', ' ', ' '))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, lines=set(range(5)))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.assertTrue(s.line(0).cursor_from(1).bold)
|
2016-10-19 11:19:27 +03:00
|
|
|
init()
|
2016-11-13 14:31:45 +03:00
|
|
|
s.erase_in_display(2, True)
|
|
|
|
self.ae(all_lines(s), (' ', ' ', ' ', ' ', ' '))
|
2016-11-11 16:05:26 +03:00
|
|
|
self.assertChanges(s, lines=set(range(5)))
|
2016-10-20 21:35:50 +03:00
|
|
|
self.assertFalse(s.line(0).cursor_from(1).bold)
|
2016-10-19 17:45:07 +03:00
|
|
|
|
2016-11-08 07:23:51 +03:00
|
|
|
def test_cursor_movement(self):
|
2016-11-11 16:05:26 +03:00
|
|
|
s = self.create_screen()
|
2016-10-19 17:45:07 +03:00
|
|
|
s.draw(b'12345' * 5)
|
2016-11-11 16:05:26 +03:00
|
|
|
s.reset_dirty()
|
2016-10-19 17:45:07 +03:00
|
|
|
s.cursor_up(2)
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (4, 2))
|
|
|
|
s.cursor_up1()
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (0, 1))
|
|
|
|
s.cursor_forward(3)
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (3, 1))
|
|
|
|
s.cursor_back()
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (2, 1))
|
|
|
|
s.cursor_down()
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (2, 2))
|
|
|
|
s.cursor_down1(5)
|
|
|
|
self.ae((s.cursor.x, s.cursor.y), (0, 4))
|
2016-11-10 10:24:38 +03:00
|
|
|
|
2016-11-11 16:05:26 +03:00
|
|
|
s = self.create_screen()
|
2016-11-10 10:24:38 +03:00
|
|
|
s.draw(b'12345' * 5)
|
|
|
|
s.index()
|
|
|
|
self.ae(str(s.line(4)), ' ' * 5)
|
2016-11-10 10:25:36 +03:00
|
|
|
for i in range(4):
|
|
|
|
self.ae(str(s.line(i)), '12345')
|
2016-11-10 10:24:38 +03:00
|
|
|
s.draw(b'12345' * 5)
|
|
|
|
s.cursor_up(5)
|
|
|
|
s.reverse_index()
|
|
|
|
self.ae(str(s.line(0)), ' ' * 5)
|
2016-11-10 10:25:36 +03:00
|
|
|
for i in range(1, 5):
|
|
|
|
self.ae(str(s.line(i)), '12345')
|