From 5926a75cc5844a970f2c088ffd52ba4e86d9ab0a Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 15 Mar 2022 17:46:18 +0100 Subject: [PATCH] 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. --- doc_src/interactive.rst | 4 ++-- src/highlight.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc_src/interactive.rst b/doc_src/interactive.rst index c2bc31573..0f0db029c 100644 --- a/doc_src/interactive.rst +++ b/doc_src/interactive.rst @@ -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: diff --git a/src/highlight.cpp b/src/highlight.cpp index 67e582b81..4d30fc9b7 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -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.