highlight: Also use the fallback variable if the main is empty

Currently, when a variable like $fish_color_command is set but empty:

    set -g fish_color_command

what happens is that highlight parses it and ends up with a "normal"
color.

Change it so instead it sees that the variable is empty and goes
on to check the fallback variable, e.g. fish_color_normal.

That makes it easier to make themes that override variables.

This means that older themes that expect an empty variable to be
"normal" need to be updated to set it to "normal".

Following from this, we could make writing .theme files easier by no
longer requiring them to list all variables with specific values.
Either the theme reader could be updated to implicitly set known color
variables to empty, or the themes could feature empty values.

See #8787.
This commit is contained in:
Fabian Homborg 2022-03-15 17:46:18 +01:00
parent f8163f5d22
commit 5926a75cc5
2 changed files with 4 additions and 4 deletions

View file

@ -134,7 +134,7 @@ Variable Meaning
``fish_color_search_match`` history search matches and selected pager items (background only)
========================================== =====================================================================
If a variable isn't set, fish usually tries ``$fish_color_normal``, except for:
If a variable isn't set or is empty, fish usually tries ``$fish_color_normal``, except for:
- ``$fish_color_keyword``, where it tries ``$fish_color_command`` first.
- ``$fish_color_option``, where it tries ``$fish_color_param`` first.
@ -178,7 +178,7 @@ Variable Meaning
``fish_pager_color_secondary_description`` description of every second unselected completion
========================================== ===========================================================
When the secondary or selected variables aren't set, the normal variables are used, except for ``$fish_pager_color_selected_background``, where the background of ``$fish_color_search_match`` is tried first.
When the secondary or selected variables aren't set or are empty, the normal variables are used, except for ``$fish_pager_color_selected_background``, where the background of ``$fish_color_search_match`` is tried first.
.. _abbreviations:

View file

@ -337,8 +337,8 @@ rgb_color_t highlight_color_resolver_t::resolve_spec_uncached(const highlight_sp
highlight_role_t role = is_background ? highlight.background : highlight.foreground;
auto var = vars.get(get_highlight_var_name(role));
if (!var) var = vars.get(get_highlight_var_name(get_fallback(role)));
if (!var) var = vars.get(get_highlight_var_name(highlight_role_t::normal));
if (var.missing_or_empty()) var = vars.get(get_highlight_var_name(get_fallback(role)));
if (var.missing_or_empty()) var = vars.get(get_highlight_var_name(highlight_role_t::normal));
if (var) result = parse_color(*var, is_background);
// Handle modifiers.