Allow specifying a value of `none for the :opt:selection_foreground`` which will cause kitty to not change text color in selections

Fixes #1358
This commit is contained in:
Kovid Goyal 2019-02-05 10:34:56 +05:30
parent 274dd2f3fe
commit eebe12a972
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 25 additions and 4 deletions

View File

@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
0.13.4 [future]
---------------------
- Allow specifying a value of ``none`` for the :opt:`selection_foreground``
which will cause kitty to not change text color in selections (:iss:`1358`)
- icat kitten: Add support for displaying images at http(s) URLs (:iss:`1340`)
- A new option :opt:`strip_trailing_spaces` to optionally remove trailing

View File

@ -5,6 +5,7 @@
#define REVERSE_SHIFT {REVERSE_SHIFT}
#define STRIKE_SHIFT {STRIKE_SHIFT}
#define DIM_SHIFT {DIM_SHIFT}
#define USE_SELECTION_FG
// Inputs {{{
layout(std140) uniform CellRenderData {
@ -171,8 +172,10 @@ void main() {
foreground = color_to_vec(resolved_fg);
float has_dim = float((text_attrs >> DIM_SHIFT) & ONE);
effective_text_alpha = inactive_text_alpha * mix(1.0, dim_opacity, has_dim);
#ifdef USE_SELECTION_FG
// Selection
foreground = choose_color(float(is_selected & ONE), color_to_vec(highlight_fg), foreground);
#endif
// Underline and strike through (rendered via sprites)
float in_url = float((is_selected & TWO) >> 1);
decoration_fg = choose_color(in_url, color_to_vec(url_color), to_color(colors[2], resolved_fg));

View File

@ -655,9 +655,16 @@ def tab_fade(x):
How much to dim text that has the DIM/FAINT attribute set. One means no dimming and
zero means fully dimmed (i.e. invisible).'''))
o('selection_foreground', '#000000', option_type=to_color, long_text=_('''
The foreground and background for text selected with the mouse'''))
o('selection_background', '#FFFACD', option_type=to_color)
def selection_foreground(x):
if x.lower() != 'none':
return to_color(x)
o('selection_foreground', '#000000', option_type=selection_foreground, long_text=_('''
The foreground for text selected with the mouse. A value of none means to leave the color unchanged.'''))
o('selection_background', '#FFFACD', option_type=to_color, long_text=_('''
The background for text selected with the mouse.'''))
g('colors.table')
o('color0', '#000000', long_text=_('black'), option_type=to_color)

View File

@ -122,6 +122,7 @@ def _run_app(opts, args):
if not is_wayland and not is_macos: # no window icons on wayland
with open(logo_data_file, 'rb') as f:
set_default_window_icon(f.read(), 256, 256)
load_shader_programs.use_selection_fg = opts.selection_foreground is not None
with cached_values_for(run_app.cached_values_name) as cached_values:
with startup_notification_handler(extra_callback=run_app.first_window_callback) as pre_show_callback:
window_id = create_os_window(

View File

@ -79,6 +79,9 @@ def color_as_vec3(x):
if semi_transparent:
vv = vv.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT')
ff = ff.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT')
if not load_shader_programs.use_selection_fg:
vv = vv.replace('#define USE_SELECTION_FG', '#define DONT_USE_SELECTION_FG')
ff = ff.replace('#define USE_SELECTION_FG', '#define DONT_USE_SELECTION_FG')
compile_program(p, vv, ff)
v, f = load_shaders('graphics')
for which, p in {
@ -90,14 +93,18 @@ def color_as_vec3(x):
init_cell_program()
load_shader_programs.use_selection_fg = True
def setup_colors(screen, opts):
screen.color_profile.update_ansi_color_table(build_ansi_color_table(opts))
cursor_text_color = opts.cursor_text_color or (12, 12, 12)
cursor_text_color_as_bg = 3 if opts.cursor_text_color is None else 1
sfg = (0, 0, 0) if opts.selection_foreground is None else opts.selection_foreground
screen.color_profile.set_configured_colors(*map(color_as_int, (
opts.foreground, opts.background, opts.cursor,
cursor_text_color, (0, 0, cursor_text_color_as_bg),
opts.selection_foreground, opts.selection_background)
sfg, opts.selection_background)
))