diff --git a/kitty/line.c b/kitty/line.c index dcf1ecb7b..9f3894317 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -583,6 +583,27 @@ left_shift(Line *self, PyObject *args) { Py_RETURN_NONE; } +static color_type +resolve_color(ColorProfile *cp, color_type val, color_type defval) { + switch(val & 0xff) { + case 1: + return cp->color_table[(val >> 8) & 0xff]; + case 2: + return val >> 8; + default: + return defval; + } +} + +bool +colors_for_cell(Line *self, ColorProfile *cp, index_type *x, color_type *fg, color_type *bg) { + if (*x >= self->xnum) return false; + if (*x > 0 && !self->gpu_cells[*x].attrs.width && self->gpu_cells[*x-1].attrs.width == 2) (*x)--; + *fg = resolve_color(cp, self->gpu_cells[*x].fg, *fg); + *bg = resolve_color(cp, self->gpu_cells[*x].bg, *bg); + return true; +} + char_type line_get_char(Line *self, index_type at) { char_type ch = self->cpu_cells[at].ch; diff --git a/kitty/lineops.h b/kitty/lineops.h index 3dd040165..578a2e29d 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -119,3 +119,4 @@ void historybuf_clear(HistoryBuf *self); void mark_text_in_line(PyObject *marker, Line *line); bool line_has_mark(Line *, uint16_t mark); PyObject* as_text_generic(PyObject *args, void *container, get_line_func get_line, index_type lines, ANSIBuf *ansibuf); +bool colors_for_cell(Line *self, ColorProfile *cp, index_type *x, color_type *fg, color_type *bg); diff --git a/kitty/screen.c b/kitty/screen.c index 8a8d61bb3..f9817c2ac 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1509,28 +1509,6 @@ screen_fake_move_cursor_to_position(Screen *self, index_type x, index_type y) { return count > 0; } -static color_type -resolve_color(ColorProfile *cp, color_type val, color_type defval) { - switch(val & 0xff) { - case 1: - return cp->color_table[(val >> 8) & 0xff]; - case 2: - return val >> 8; - default: - return defval; - } -} - -bool -resolve_cell_colors(Screen *self, index_type x, index_type y, color_type *fg, color_type *bg, color_type default_fg, color_type default_bg) { - if (x < self->columns && y < self->lines) { - linebuf_init_line(self->linebuf, y); - GPUCell *g = self->linebuf->line->gpu_cells + x; - *fg = resolve_color(self->color_profile, g->fg, default_fg); - *bg = resolve_color(self->color_profile, g->bg, default_bg); - return true; - } else { *fg = 0; *bg = 0; return false; } -} // }}} // Editing {{{ diff --git a/kitty/screen.h b/kitty/screen.h index 86352f636..50c518e7c 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -249,7 +249,6 @@ void screen_report_key_encoding_flags(Screen *self); bool screen_detect_url(Screen *screen, unsigned int x, unsigned int y); int screen_cursor_at_a_shell_prompt(const Screen *); bool screen_fake_move_cursor_to_position(Screen *, index_type x, index_type y); -bool resolve_cell_colors(Screen *self, index_type x, index_type y, color_type *fg, color_type *bg, color_type default_fg, color_type default_bg); #define DECLARE_CH_SCREEN_HANDLER(name) void screen_##name(Screen *screen); DECLARE_CH_SCREEN_HANDLER(bell) DECLARE_CH_SCREEN_HANDLER(backspace) diff --git a/kitty/shaders.c b/kitty/shaders.c index 110bfc2d4..9c329d899 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -291,8 +291,12 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G rd->cursor_fg_sprite_idx = UNDERLINE_IDX; break; } } else rd->cursor_fg_sprite_idx = UNFOCUSED_IDX; - color_type cell_fg, cell_bg; - resolve_cell_colors(screen, screen->cursor->x, screen->cursor->y, &cell_fg, &cell_bg, rd->default_fg, rd->default_bg); + color_type cell_fg = rd->default_fg, cell_bg = rd->default_bg; + if (screen->cursor->y < screen->lines) { + linebuf_init_line(screen->linebuf, screen->cursor->y); + index_type x = screen->cursor->x; + colors_for_cell(screen->linebuf->line, screen->color_profile, &x, &cell_fg, &cell_bg); + } if (screen->color_profile->overridden.cursor_color.type == COLOR_IS_INDEX || screen->color_profile->overridden.cursor_color.type == COLOR_IS_RGB) { // since the program is controlling the cursor color we hope it has chosen one // that has good contrast with the text color of the cell