diff --git a/kitty/data_types.py b/kitty/data_types.py index 9f06e2396..5ffe91959 100644 --- a/kitty/data_types.py +++ b/kitty/data_types.py @@ -141,6 +141,12 @@ class Line: if clear_char: self.width[at], self.char[at] = repeat(1, num), repeat(ord(char), num) + def cursor_from(self, x: int, ypos: int=0) -> Cursor: + c = Cursor(x, ypos) + c.fg, c.bg, c.decoration, c.decoration_fg = self.fg[x], self.bg[x], self.decoration[x], self.decoration_fg[x] + c.bold, c.italic, c.reverse, c.strikethrough = bool(self.bold[x]), bool(self.italic[x]), bool(self.reverse[x]), bool(self.strikethrough[x]) + return c + def copy_slice(self, src, dest, num): src, dest = slice(src, src + num), slice(dest, dest + num) for a in (self.char, self.fg, self.bg, self.bold, self.italic, self.reverse, self.strikethrough, self.decoration, self.decoration_fg, self.width): diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index a27168a14..2a70abe96 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -30,5 +30,10 @@ class TestDataTypes(BaseTest): self.ae(c, c) c2 = c.copy() self.ae(c, c.copy()) - c2.bold = False + c2.bold = c2.hidden = False self.assertNotEqual(c, c2) + l.apply_cursor(c2, 3) + self.ae(c2, l.cursor_from(3, ypos=c2.y)) + l.apply_cursor(c2, 0, len(l)) + for i in range(len(l)): + self.ae(c2, l.cursor_from(i, ypos=c2.y))