From 0a69f00ab4efe2b2a33f19044a7e749494c6f16c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 8 Nov 2016 09:53:51 +0530 Subject: [PATCH] Re-enable all screen tests --- kitty/data-types.h | 2 +- kitty/line-buf.c | 1 + kitty/line.c | 12 ++++++++++++ kitty/screen.py | 15 +++++++-------- kitty_tests/screen.py | 14 +++++++------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 3394dc8c6..e9d6f4f06 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -25,7 +25,7 @@ typedef unsigned int index_type; #define CHAR_MASK 0xFFFFFF #define ATTRS_SHIFT 24 #define ATTRS_MASK_WITHOUT_WIDTH 0xFC000000 -#define WIDTH_MASK 0xFF +#define WIDTH_MASK 3 #define DECORATION_SHIFT 2 #define BOLD_SHIFT 4 #define ITALIC_SHIFT 5 diff --git a/kitty/line-buf.c b/kitty/line-buf.c index fea6b518e..1a7eeeae6 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -97,6 +97,7 @@ line(LineBuf *self, PyObject *y) { } self->line->ynum = idx; self->line->xnum = self->xnum; + self->line->continued = self->continued_map[idx]; INIT_LINE(self, self->line, self->line_map[idx]); Py_INCREF(self->line); return (PyObject*)self->line; diff --git a/kitty/line.c b/kitty/line.c index 4eeef9a1c..c7b3cef6d 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -62,6 +62,8 @@ as_unicode(Line* self) { return NULL; } for(index_type i = 0; i < self->xnum; i++) { + char_type attrs = self->chars[i] >> ATTRS_SHIFT; + if ((attrs & WIDTH_MASK) < 1) continue; buf[n++] = self->chars[i] & CHAR_MASK; char_type cc = self->combining_chars[i]; Py_UCS4 cc1 = cc & CC_MASK, cc2; @@ -76,6 +78,15 @@ as_unicode(Line* self) { return ans; } +static PyObject* +width(Line *self, PyObject *val) { +#define width_doc "width_doc(x) -> the width of the character at x" + unsigned long x = PyLong_AsUnsignedLong(val); + if (x >= self->xnum) { PyErr_SetString(PyExc_ValueError, "Out of bounds"); return NULL; } + char_type attrs = self->chars[x] >> ATTRS_SHIFT; + return PyLong_FromUnsignedLong((unsigned long) (attrs & WIDTH_MASK)); +} + static PyObject* add_combining_char(Line* self, PyObject *args) { #define add_combining_char_doc "add_combining_char(x, ch) -> Add the specified character as a combining char to the specified cell." @@ -313,6 +324,7 @@ static PyMethodDef methods[] = { METHOD(left_shift, METH_VARARGS) METHOD(set_char, METH_VARARGS) METHOD(set_attribute, METH_VARARGS) + METHOD(width, METH_O) {NULL} /* Sentinel */ }; diff --git a/kitty/screen.py b/kitty/screen.py index 866afcf15..ba38b9bb0 100644 --- a/kitty/screen.py +++ b/kitty/screen.py @@ -9,10 +9,9 @@ from collections import deque, namedtuple from typing import Sequence from pyte import charsets as cs, graphics as g, modes as mo -from .data_types import Line, Cursor, rewrap_lines from .utils import wcwidth, is_simple_string, sanitize_title from .unicode import ignore_pat -from .fast_data_types import LineBuf, REVERSE +from .fast_data_types import LineBuf, REVERSE, Cursor #: A container for screen's scroll margins. @@ -91,7 +90,7 @@ class Screen: @property def display(self) -> Sequence[str]: - return tuple(map(str, self.linebuf)) + return tuple(map(lambda l: str(self.linebuf.line(l)), range(self.linebuf.ynum))) def toggle_screen_buffer(self): self.save_cursor() @@ -609,7 +608,7 @@ class Screen: num = min(self.columns - x, count) line = self.linebuf.line(y) line.right_shift(x, num) - line.apply_cursor(self.cursor, x, num, clear_char=True) + line.apply_cursor(self.cursor, x, num, True) self.update_cell_range(y, x, self.columns - 1) def delete_characters(self, count=1): @@ -633,7 +632,7 @@ class Screen: # cell of a wide character? line = self.linebuf.line(y) line.left_shift(x, num) - line.apply_cursor(self.cursor, self.columns - num, num, clear_char=True) + line.apply_cursor(self.cursor, self.columns - num, num, True) self.update_cell_range(y, x, self.columns - 1) def erase_characters(self, count=1): @@ -655,7 +654,7 @@ class Screen: # TODO: Same set of wide character questions as for delete_characters() num = min(self.columns - x, count) l = self.linebuf.line(y) - l.apply_cursor(self.cursor, x, num, clear_char=True) + l.apply_cursor(self.cursor, x, num, True) self.update_cell_range(y, x, min(x + num, self.columns) - 1) def erase_in_line(self, how=0, private=False): @@ -691,7 +690,7 @@ class Screen: if private: line.clear_text(s, n) else: - line.apply_cursor(c, s, n, clear_char=True) + line.apply_cursor(c, s, n, True) self.update_cell_range(y, s, min(s + n, self.columns) - 1) def erase_in_display(self, how=0, private=False): @@ -726,7 +725,7 @@ class Screen: if private: self.linebuf.line(line).clear_text(0, self.columns) else: - self.linebuf.line(line).apply_cursor(self.cursor, 0, self.columns, clear_char=True) + self.linebuf.line(line).apply_cursor(self.cursor, 0, self.columns, True) self.update_line_range(interval[0], interval[1] - 1) # In case of 0 or 1 we have to erase the line with the cursor also diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index e4320678f..ab69a0a63 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -9,7 +9,7 @@ from kitty.screen import mo class TestScreen(BaseTest): - def xtest_draw_fast(self): + def test_draw_fast(self): # Test in line-wrap, non-insert mode s, t = self.create_screen() s.draw(b'a' * 5) @@ -17,8 +17,8 @@ class TestScreen(BaseTest): 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.line(1).continued) - self.assertTrue(s.line(2).continued) + self.assertTrue(s.linebuf.is_continued(1)) + 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) @@ -52,7 +52,7 @@ class TestScreen(BaseTest): self.ae((s.cursor.x, s.cursor.y), (2, 4)) self.assertChanges(t, ignore='cursor', cells={4: ((0, 4),)}) - def xtest_draw_char(self): + def test_draw_char(self): # Test in line-wrap, non-insert mode s, t = self.create_screen() s.draw('ココx'.encode('utf-8')) @@ -101,7 +101,7 @@ class TestScreen(BaseTest): self.ae((s.cursor.x, s.cursor.y), (2, 4)) self.assertChanges(t, ignore='cursor', cells={4: ((0, 4),)}) - def xtest_char_manipulation(self): + def test_char_manipulation(self): s, t = self.create_screen() def init(): @@ -162,7 +162,7 @@ class TestScreen(BaseTest): s.erase_in_line(2, private=True) self.ae((False, False, False, False, False), tuple(map(lambda i: s.line(0).cursor_from(i).bold, range(5)))) - def xtest_erase_in_screen(self): + def test_erase_in_screen(self): s, t = self.create_screen() def init(): @@ -193,7 +193,7 @@ class TestScreen(BaseTest): self.assertChanges(t, lines=set(range(5))) self.assertFalse(s.line(0).cursor_from(1).bold) - def xtest_cursor_movement(self): + def test_cursor_movement(self): s, t = self.create_screen() s.draw(b'12345' * 5) t.reset()