From ebce1d7c61ed99887f70a3992f2e68e737fb3675 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Aug 2017 21:57:22 +0530 Subject: [PATCH] Fix incorrect handling of escape codes to change default foreground and background colors. Fixes #104 --- kitty/char_grid.py | 15 +++++++-------- kitty/screen.c | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/kitty/char_grid.py b/kitty/char_grid.py index f5c272fe4..f65cfa5cc 100644 --- a/kitty/char_grid.py +++ b/kitty/char_grid.py @@ -297,7 +297,7 @@ class CharGrid: if raw is None: return 0 val = to_color(raw) - return None if val is None else (color_as_int(val) << 8) | 1 + return None if val is None else (color_as_int(val) << 8) | 2 for which, val in changes.items(): val = item(val) @@ -322,10 +322,9 @@ class CharGrid: sprites = get_boss().sprites is_dirty = self.screen.is_dirty() with sprites.lock: - fg = self.screen.default_fg - fg = fg >> 8 if fg & 1 else self.default_fg - bg = self.screen.default_bg - bg = bg >> 8 if bg & 1 else self.default_bg + fg, bg = self.screen.default_fg, self.screen.default_bg + fg = fg >> 8 if fg & 2 else self.default_fg + bg = bg >> 8 if bg & 2 else self.default_bg cursor_changed, history_line_added_count = self.screen.update_cell_data( sprites.backend, self.color_profile, addressof(self.main_sprite_map), fg, bg, force_full_refresh) if self.scrolled_by: @@ -475,9 +474,9 @@ class CharGrid: if self.render_buf_is_dirty or sel != self.last_rendered_selection: memmove(buf, self.render_buf, sizeof(type(buf))) fg = self.screen.highlight_fg - fg = fg >> 8 if fg & 1 else self.highlight_fg + fg = fg >> 8 if fg & 2 else self.highlight_fg bg = self.screen.highlight_bg - bg = bg >> 8 if bg & 1 else self.highlight_bg + bg = bg >> 8 if bg & 2 else self.highlight_bg self.screen.apply_selection(addressof(buf), start[0], start[1], end[0], end[1], fg, bg) if self.render_buf_is_dirty or self.last_rendered_selection != sel: sprites.set_sprite_map(self.buffer_id, buf) @@ -503,7 +502,7 @@ class CharGrid: left = sg.xstart + cursor.x * sg.dx top = sg.ystart - cursor.y * sg.dy cc = self.screen.cursor_color - col = color_from_int(cc >> 8) if cc & 1 else self.opts.cursor + col = color_from_int(cc >> 8) if cc & 2 else self.opts.cursor shape = cursor.shape or self.default_cursor.shape alpha = self.opts.cursor_opacity if alpha < 1.0 and shape == CURSOR_BLOCK: diff --git a/kitty/screen.c b/kitty/screen.c index 797a30ad8..5f3b9e47d 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -7,6 +7,7 @@ #include "data-types.h" #include +#include #include "unicode-data.h" #include "tracker.h" #include "modes.h" @@ -1332,6 +1333,14 @@ static PyGetSetDef getsetters[] = { {NULL} /* Sentinel */ }; +#if UINT_MAX == UINT32_MAX +#define T_COL T_UINT +#elif ULONG_MAX == UINT32_MAX +#define T_COL T_ULONG +#else +#error Neither int nor long is 4-bytes in size +#endif + static PyMemberDef members[] = { {"callbacks", T_OBJECT_EX, offsetof(Screen, callbacks), 0, "callbacks"}, {"cursor", T_OBJECT_EX, offsetof(Screen, cursor), READONLY, "cursor"}, @@ -1341,11 +1350,11 @@ static PyMemberDef members[] = { {"columns", T_UINT, offsetof(Screen, columns), READONLY, "columns"}, {"margin_top", T_UINT, offsetof(Screen, margin_top), READONLY, "margin_top"}, {"margin_bottom", T_UINT, offsetof(Screen, margin_bottom), READONLY, "margin_bottom"}, - {"default_fg", T_ULONG, offsetof(Screen, default_fg), 0, "default_fg"}, - {"default_bg", T_ULONG, offsetof(Screen, default_bg), 0, "default_bg"}, - {"highlight_fg", T_ULONG, offsetof(Screen, highlight_fg), 0, "highlight_fg"}, - {"highlight_bg", T_ULONG, offsetof(Screen, highlight_bg), 0, "highlight_bg"}, - {"cursor_color", T_ULONG, offsetof(Screen, cursor_color), 0, "cursor_color"}, + {"default_fg", T_COL, offsetof(Screen, default_fg), 0, "default_fg"}, + {"default_bg", T_COL, offsetof(Screen, default_bg), 0, "default_bg"}, + {"highlight_fg", T_COL, offsetof(Screen, highlight_fg), 0, "highlight_fg"}, + {"highlight_bg", T_COL, offsetof(Screen, highlight_bg), 0, "highlight_bg"}, + {"cursor_color", T_COL, offsetof(Screen, cursor_color), 0, "cursor_color"}, {NULL} };