Allow reverse video for the mouse selection

Fixes #646
This commit is contained in:
Kovid Goyal 2021-10-28 15:01:48 +05:30
parent 28386cc496
commit 702bfccfa2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 22 additions and 17 deletions

View File

@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Allow rendering the cursor with a *reverse video* effect. See :opt:`cursor` - Allow rendering the cursor with a *reverse video* effect. See :opt:`cursor`
for details (:iss:`126`) for details (:iss:`126`)
- Allow rendering the mouse selection with a *reverse video* effect. See
:opt:`selection_foreground` (:iss:`646`)
- A new option :opt:`tab_bar_align` to draw the tab bar centered or right - A new option :opt:`tab_bar_align` to draw the tab bar centered or right
aligned (:iss:`3946`) aligned (:iss:`3946`)

View File

@ -12,7 +12,7 @@
// Inputs {{{ // Inputs {{{
layout(std140) uniform CellRenderData { layout(std140) uniform CellRenderData {
float xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, use_fg_for_selection; float xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, use_cell_for_selection_fg, use_cell_for_selection_bg;
uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_fg, cursor_bg, url_color, url_style, inverted; uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_fg, cursor_bg, url_color, url_style, inverted;
@ -170,6 +170,7 @@ void main() {
uint bg_as_uint = resolve_color(colors[bg_index], default_colors[bg_index]); uint bg_as_uint = resolve_color(colors[bg_index], default_colors[bg_index]);
bg_as_uint = has_mark * color_table[NUM_COLORS + mark] + (ONE - has_mark) * bg_as_uint; bg_as_uint = has_mark * color_table[NUM_COLORS + mark] + (ONE - has_mark) * bg_as_uint;
vec3 bg = color_to_vec(bg_as_uint); vec3 bg = color_to_vec(bg_as_uint);
uint fg_as_uint = resolve_color(colors[fg_index], default_colors[fg_index]);
// }}} // }}}
// Foreground {{{ // Foreground {{{
@ -180,7 +181,6 @@ void main() {
colored_sprite = float((sprite_coords.z & COLOR_MASK) >> 14); colored_sprite = float((sprite_coords.z & COLOR_MASK) >> 14);
// Foreground // Foreground
uint fg_as_uint = resolve_color(colors[fg_index], default_colors[fg_index]);
fg_as_uint = has_mark * color_table[NUM_COLORS + MARK_MASK + 1 + mark] + (ONE - has_mark) * fg_as_uint; fg_as_uint = has_mark * color_table[NUM_COLORS + MARK_MASK + 1 + mark] + (ONE - has_mark) * fg_as_uint;
foreground = color_to_vec(fg_as_uint); foreground = color_to_vec(fg_as_uint);
float has_dim = float((text_attrs >> DIM_SHIFT) & ONE); float has_dim = float((text_attrs >> DIM_SHIFT) & ONE);
@ -189,7 +189,7 @@ void main() {
decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], fg_as_uint)); decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], fg_as_uint));
#ifdef USE_SELECTION_FG #ifdef USE_SELECTION_FG
// Selection // Selection
vec3 selection_color = choose_color(use_fg_for_selection, foreground, color_to_vec(highlight_fg)); vec3 selection_color = choose_color(use_cell_for_selection_fg, bg, color_to_vec(highlight_fg));
foreground = choose_color(float(is_selected & ONE), selection_color, foreground); foreground = choose_color(float(is_selected & ONE), selection_color, foreground);
decoration_fg = choose_color(float(is_selected & ONE), selection_color, decoration_fg); decoration_fg = choose_color(float(is_selected & ONE), selection_color, decoration_fg);
#endif #endif
@ -236,7 +236,7 @@ void main() {
#if defined(SPECIAL) || defined(SIMPLE) #if defined(SPECIAL) || defined(SIMPLE)
// Selection and cursor // Selection and cursor
bg = choose_color(float(is_selected & ONE), color_to_vec(highlight_bg), bg); bg = choose_color(float(is_selected & ONE), choose_color(use_cell_for_selection_bg, color_to_vec(fg_as_uint), color_to_vec(highlight_bg)), bg);
background = choose_color(cell_has_block_cursor, color_to_vec(cursor_bg), bg); background = choose_color(cell_has_block_cursor, color_to_vec(cursor_bg), bg);
#if !defined(TRANSPARENT) && defined(SPECIAL) #if !defined(TRANSPARENT) && defined(SPECIAL)
float is_special_cell = cell_has_block_cursor + float(is_selected & ONE); float is_special_cell = cell_has_block_cursor + float(is_selected & ONE);

View File

@ -1146,15 +1146,13 @@ and zero means fully dimmed (i.e. invisible).
opt('selection_foreground', '#000000', opt('selection_foreground', '#000000',
option_type='to_color_or_none', option_type='to_color_or_none',
long_text=''' long_text='''
The foreground for text selected with the mouse. A value of none means to leave The foreground and background colors for text selected with the mouse. Setting both of
the color unchanged. these to :code:`none` will cause a "reverse video" effect for selections, where the
''' selection will be the cell text color and the text will become the cell background color.
) Note that these colors can be overridden by the program running in the terminal.
''')
opt('selection_background', '#fffacd', opt('selection_background', '#fffacd', option_type='to_color_or_none',)
option_type='to_color',
long_text='The background for text selected with the mouse.'
)
# colors.table {{{ # colors.table {{{

View File

@ -1125,7 +1125,7 @@ class Parser:
ans['select_by_word_characters'] = str(val) ans['select_by_word_characters'] = str(val)
def selection_background(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def selection_background(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['selection_background'] = to_color(val) ans['selection_background'] = to_color_or_none(val)
def selection_foreground(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def selection_foreground(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['selection_foreground'] = to_color_or_none(val) ans['selection_foreground'] = to_color_or_none(val)

View File

@ -537,7 +537,7 @@ class Options:
scrollback_pager: typing.List[str] = ['less', '--chop-long-lines', '--RAW-CONTROL-CHARS', '+INPUT_LINE_NUMBER'] scrollback_pager: typing.List[str] = ['less', '--chop-long-lines', '--RAW-CONTROL-CHARS', '+INPUT_LINE_NUMBER']
scrollback_pager_history_size: int = 0 scrollback_pager_history_size: int = 0
select_by_word_characters: str = '@-./_~?&=%+#' select_by_word_characters: str = '@-./_~?&=%+#'
selection_background: Color = Color(255, 250, 205) selection_background: typing.Optional[kitty.fast_data_types.Color] = Color(255, 250, 205)
selection_foreground: typing.Optional[kitty.fast_data_types.Color] = Color(0, 0, 0) selection_foreground: typing.Optional[kitty.fast_data_types.Color] = Color(0, 0, 0)
shell: str = '.' shell: str = '.'
shell_integration: str = 'enabled' shell_integration: str = 'enabled'

View File

@ -17,7 +17,10 @@ if TYPE_CHECKING:
from kitty.cli_stub import SetColorsRCOptions as CLIOptions from kitty.cli_stub import SetColorsRCOptions as CLIOptions
nullable_colors = ('cursor', 'cursor_text_color', 'tab_bar_background', 'tab_bar_margin_color', 'selection_foreground', 'active_border_color') nullable_colors = (
'cursor', 'cursor_text_color', 'tab_bar_background', 'tab_bar_margin_color',
'selection_foreground', 'selection_background', 'active_border_color'
)
def parse_colors(args: Iterable[str]) -> Dict[str, Optional[int]]: def parse_colors(args: Iterable[str]) -> Dict[str, Optional[int]]:

View File

@ -276,7 +276,7 @@ pick_cursor_color(Line *line, ColorProfile *color_profile, color_type cell_fg, c
static void static void
cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, CursorRenderInfo *cursor, bool inverted, OSWindow *os_window) { cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, CursorRenderInfo *cursor, bool inverted, OSWindow *os_window) {
struct CellRenderData { struct CellRenderData {
GLfloat xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, use_fg_for_selection; GLfloat xstart, ystart, dx, dy, sprite_dx, sprite_dy, background_opacity, use_cell_for_selection_fg, use_cell_for_selection_bg;
GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_fg, cursor_bg, url_color, url_style, inverted; GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_fg, cursor_bg, url_color, url_style, inverted;
@ -295,7 +295,8 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G
rd->default_fg = COLOR(default_fg); rd->default_bg = COLOR(default_bg); rd->default_fg = COLOR(default_fg); rd->default_bg = COLOR(default_bg);
rd->highlight_fg = COLOR(highlight_fg); rd->highlight_bg = COLOR(highlight_bg); rd->highlight_fg = COLOR(highlight_fg); rd->highlight_bg = COLOR(highlight_bg);
// selection // selection
rd->use_fg_for_selection = IS_SPECIAL_COLOR(highlight_fg) ? 1. : 0.; rd->use_cell_for_selection_fg = IS_SPECIAL_COLOR(highlight_fg) ? 1. : 0.;
rd->use_cell_for_selection_bg = IS_SPECIAL_COLOR(highlight_bg) ? 1. : 0.;
// Cursor position // Cursor position
enum { BLOCK_IDX = 0, BEAM_IDX = 6, UNDERLINE_IDX = 7, UNFOCUSED_IDX = 8 }; enum { BLOCK_IDX = 0, BEAM_IDX = 6, UNDERLINE_IDX = 7, UNFOCUSED_IDX = 8 };
if (cursor->is_visible) { if (cursor->is_visible) {