2019-05-20 13:38:06 +03:00
|
|
|
#!/usr/bin/env python3
|
2016-10-16 18:06:27 +03:00
|
|
|
# vim:fileencoding=utf-8
|
|
|
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2018-09-15 19:40:13 +03:00
|
|
|
from kitty.config import Options, defaults, merge_configs
|
|
|
|
from kitty.fast_data_types import set_options
|
2016-11-20 18:05:30 +03:00
|
|
|
from kitty.fast_data_types import LineBuf, Cursor, Screen, HistoryBuf
|
2016-11-04 12:14:46 +03:00
|
|
|
|
|
|
|
|
2016-11-24 13:58:08 +03:00
|
|
|
class Callbacks:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.clear()
|
|
|
|
|
2017-09-16 14:35:58 +03:00
|
|
|
def write(self, data):
|
2016-11-24 13:58:08 +03:00
|
|
|
self.wtcbuf += data
|
|
|
|
|
|
|
|
def title_changed(self, data):
|
|
|
|
self.titlebuf += data
|
|
|
|
|
|
|
|
def icon_changed(self, data):
|
|
|
|
self.iconbuf += data
|
|
|
|
|
|
|
|
def set_dynamic_color(self, code, data):
|
|
|
|
self.colorbuf += data or ''
|
|
|
|
|
|
|
|
def set_color_table_color(self, code, data):
|
|
|
|
self.ctbuf += ''
|
|
|
|
|
|
|
|
def request_capabilities(self, q):
|
2017-12-02 12:05:06 +03:00
|
|
|
from kitty.terminfo import get_capabilities
|
2017-12-03 14:27:08 +03:00
|
|
|
c = get_capabilities(q)
|
|
|
|
self.write(c.encode('ascii'))
|
2016-11-24 13:58:08 +03:00
|
|
|
|
2017-04-28 07:11:47 +03:00
|
|
|
def use_utf8(self, on):
|
|
|
|
self.iutf8 = on
|
|
|
|
|
2016-11-24 13:58:08 +03:00
|
|
|
def clear(self):
|
|
|
|
self.wtcbuf = b''
|
2017-12-02 12:05:06 +03:00
|
|
|
self.iconbuf = self.titlebuf = self.colorbuf = self.ctbuf = ''
|
2017-04-28 07:11:47 +03:00
|
|
|
self.iutf8 = True
|
2016-11-24 13:58:08 +03:00
|
|
|
|
|
|
|
|
2016-11-04 12:14:46 +03:00
|
|
|
def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()):
|
|
|
|
ans = LineBuf(ynum, xnum)
|
|
|
|
cursor.x = 0
|
|
|
|
for i in range(ynum):
|
|
|
|
t = ('{}'.format(i)) * xnum
|
|
|
|
ans.line(i).set_text(t, 0, xnum, cursor)
|
|
|
|
return ans
|
2016-10-18 08:34:30 +03:00
|
|
|
|
2016-10-16 18:06:27 +03:00
|
|
|
|
2016-11-04 12:26:31 +03:00
|
|
|
def filled_cursor():
|
|
|
|
ans = Cursor()
|
2018-05-20 08:13:26 +03:00
|
|
|
ans.bold = ans.italic = ans.reverse = ans.strikethrough = ans.dim = True
|
2016-11-04 12:26:31 +03:00
|
|
|
ans.fg = 0x101
|
|
|
|
ans.bg = 0x201
|
|
|
|
ans.decoration_fg = 0x301
|
|
|
|
return ans
|
|
|
|
|
|
|
|
|
2016-11-20 18:05:30 +03:00
|
|
|
def filled_history_buf(ynum=5, xnum=5, cursor=Cursor()):
|
|
|
|
lb = filled_line_buf(ynum, xnum, cursor)
|
|
|
|
ans = HistoryBuf(ynum, xnum)
|
|
|
|
for i in range(ynum):
|
|
|
|
ans.push(lb.line(i))
|
|
|
|
return ans
|
|
|
|
|
|
|
|
|
2016-10-16 18:06:27 +03:00
|
|
|
class BaseTest(TestCase):
|
|
|
|
|
|
|
|
ae = TestCase.assertEqual
|
2017-09-25 18:24:36 +03:00
|
|
|
maxDiff = 2000
|
2016-10-18 08:34:30 +03:00
|
|
|
|
2018-11-20 08:12:17 +03:00
|
|
|
def create_screen(self, cols=5, lines=5, scrollback=5, cell_width=10, cell_height=20, options=None):
|
2020-02-13 06:03:57 +03:00
|
|
|
final_options = {'scrollback_pager_history_size': 1024, 'click_interval': 0.5}
|
|
|
|
if options:
|
|
|
|
final_options.update(options)
|
|
|
|
options = Options(merge_configs(defaults._asdict(), final_options))
|
2018-09-15 19:40:13 +03:00
|
|
|
set_options(options)
|
2017-09-16 14:35:58 +03:00
|
|
|
c = Callbacks()
|
2018-05-25 08:58:46 +03:00
|
|
|
return Screen(c, lines, cols, scrollback, cell_width, cell_height, 0, c)
|
2016-10-18 08:34:30 +03:00
|
|
|
|
2016-11-02 08:14:35 +03:00
|
|
|
def assertEqualAttributes(self, c1, c2):
|
|
|
|
x1, y1, c1.x, c1.y = c1.x, c1.y, 0, 0
|
|
|
|
x2, y2, c2.x, c2.y = c2.x, c2.y, 0, 0
|
|
|
|
try:
|
|
|
|
self.assertEqual(c1, c2)
|
|
|
|
finally:
|
|
|
|
c1.x, c1.y, c2.x, c2.y = x1, y1, x2, y2
|