Fix bad contrast in search match highlighting

This is another problem that has been bothering me for years: as mentioned
in 1dd901e52 (Maintain cursor in history prefix search, 2024-04-12), up-arrow
search highlights search matches but the contrast is really bad, especially in
command position, because the search matches --background=brblack is combined
with whatever foreground syntax highlighting the command has.  The history
pager had a similar problem (for the selected history item) but circumented
it by disabling syntax highlighting altogether for the selected item.

fish_color_search_match's foreground component is ignored.
Let's use it instead of syntax highlighting.

This fixes the contrast on some default colorschemes but the bryellow
foreground looks weirdly like an error/warning on some terminals.  Change it
to white. This needs a hack because we don't have a canonical way to tell
if a uvar has been set by the user. Fortunately the foreground component
hasn't been used at all so far, so we're not so much changing it as much as
initializing it.
This commit is contained in:
Johannes Altmanninger 2024-04-15 09:06:00 +02:00
parent 27b1f28108
commit 9af6a64fd2
3 changed files with 12 additions and 5 deletions

View File

@ -101,6 +101,7 @@ Interactive improvements
- Completions that insert an entire token now use quotes instead of backslashes to escape special characters (:issue:`5433`).
- Autosuggestions were sometimes not shown after recalling a line from history, which has been fixed (:issue:`10287`).
- Nonprintable ASCII control characters are now rendered using symbols from Unicode's Control Pictures block (:issue:`5274`).
- Up-arrow search matches are no longer highlighted with low contrast.
- When a command like ``fg %2`` fails to find the given job, it no longer behaves as if no job spec was given (:issue:`9835`).
- Redirection in command position like ``>echo`` is now highlighted as error (:issue:`8877`).
- `fish_vi_cursor` now works properly inside the prompt created by builtin ``read`` (:issue:`10088`).

View File

@ -55,9 +55,6 @@ end" >$__fish_config_dir/config.fish
__init_uvar fish_color_cwd green
__init_uvar fish_color_cwd_root red
# Background color for search matches
__init_uvar fish_color_search_match bryellow --background=brblack
# Background color for selections
__init_uvar fish_color_selection white --bold --background=brblack
@ -75,6 +72,13 @@ end" >$__fish_config_dir/config.fish
#
__init_uvar fish_color_history_current --bold
end
if test $__fish_initialized -lt 3800
# Background color for search matches
__init_uvar fish_color_search_match white --background=brblack
if test "$fish_color_search_match[1]" = bryellow
set --universal fish_color_search_match[1] white
end
end
#
# Generate man page completions if not present.
@ -227,7 +231,7 @@ end" >$__fish_config_dir/config.fish
# Bump this whenever some code below needs to run once when upgrading to a new version.
# The universal variable __fish_initialized is initialized in share/config.fish.
set __fish_initialized 3400
set __fish_initialized 3800
functions -e __fish_config_interactive
end

View File

@ -1433,6 +1433,7 @@ impl ReaderData {
}
for color in &mut colors[data.history_search_range.unwrap().start()..end] {
color.foreground = HighlightRole::search_match;
color.background = HighlightRole::search_match;
}
}
@ -3316,7 +3317,8 @@ impl ReaderData {
// Save off the colors and set the background.
let saved_colors = data.colors.clone();
for i in 0..self.command_line.position() {
data.colors[i] = HighlightSpec::with_bg(HighlightRole::search_match);
data.colors[i].foreground = HighlightRole::search_match;
data.colors[i].background = HighlightRole::search_match;
}
self.rendered_layout = data.clone(); // need to copy the data since we will use it again.
self.paint_layout(L!("flash"));