fish_config: Set colors that aren't set in the theme to empty

This allows keeping it to the fallback value, making us independent
from the theme that was set before.
This commit is contained in:
Fabian Homborg 2022-03-19 13:46:16 +01:00
parent 751c7cbf9c
commit edbd3baa59
2 changed files with 68 additions and 3 deletions

View File

@ -236,7 +236,15 @@ function fish_config --description "Launch fish's web based configuration"
return 1
end
set -l have_color 0
set -l known_colors fish_color_{normal,command,keyword,quote,redirection,\
end,error,param,option,comment,selection,operator,escape,autosuggestion,\
cwd,user,host,host_remote,cancel,search_match} \
fish_pager_color_{progress,background,prefix,completion,description,\
selected_background,selected_prefix,selected_completion,selected_description,\
secondary_background,secondary_prefix,secondary_completion,secondary_description}
set -l have_colors
while read -lat toks
# We only allow color variables.
# Not the specific list, but something named *like* a color variable.
@ -251,11 +259,19 @@ function fish_config --description "Launch fish's web based configuration"
set -eg $toks[1]
end
set $scope $toks
set have_color 1
set -a have_colors $toks[1]
end <$file
# Set all colors that aren't mentioned to empty
for c in $known_colors
contains -- $c $have_colors
and continue
set $scope $c
end
# Return true if we changed at least one color
test $have_color -eq 1
set -q have_colors[1]
return
case dump
# Write the current theme in .theme format, to stdout.

View File

@ -1467,13 +1467,62 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
if p == "/set_color/":
print("# Colorscheme: " + postvars.get("theme"))
have_colors = set()
known_colors = set(
(
"fish_color_normal",
"fish_color_command",
"fish_color_keyword",
"fish_color_quote",
"fish_color_redirection",
"fish_color_end",
"fish_color_error",
"fish_color_param",
"fish_color_option",
"fish_color_comment",
"fish_color_selection",
"fish_color_operator",
"fish_color_escape",
"fish_color_autosuggestion",
"fish_color_cwd",
"fish_color_user",
"fish_color_host",
"fish_color_host_remote",
"fish_color_cancel",
"fish_color_search_match",
"fish_pager_color_progress",
"fish_pager_color_background",
"fish_pager_color_prefix",
"fish_pager_color_completion",
"fish_pager_color_description",
"fish_pager_color_selected_background",
"fish_pager_color_selected_prefix",
"fish_pager_color_selected_completion",
"fish_pager_color_selected_description",
"fish_pager_color_secondary_background",
"fish_pager_color_secondary_prefix",
"fish_pager_color_secondary_completion",
"fish_pager_color_secondary_description",
)
)
for item in postvars.get("colors"):
what = item.get("what")
color = item.get("color")
if what:
if not what.startswith("fish_pager_color_") and not what.startswith(
"fish_color_"
):
have_colors.add("fish_color_" + what)
else:
have_colors.add(what)
output = self.do_set_color_for_variable(what, color)
# Set all known colors that weren't defined in this theme
# to empty, to avoid keeping around coloration from an earlier theme.
for what in known_colors - have_colors:
output += "\n" + self.do_set_color_for_variable(what, "")
elif p == "/get_function/":
what = postvars.get("what")
output = [self.do_get_function(what[0])]