mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
Webconfig: Pass colorscheme in one json request
This used to pass each color in a separate url-encoded request, which is just wasteful. Also it passed separate parameters for modifiers like bold and underlined, but never gave them actual values. Instead the color is passed as one string. So we just use json, and then iterate over it server-side.
This commit is contained in:
@@ -1075,9 +1075,11 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
return out
|
||||
|
||||
def do_set_color_for_variable(
|
||||
self, name, color, background_color, bold, underline, italics, dim, reverse
|
||||
self, name, color
|
||||
):
|
||||
"Sets a color for a fish color name, like 'autosuggestion'"
|
||||
if not name:
|
||||
raise ValueError
|
||||
if not color:
|
||||
color = "normal"
|
||||
varname = "fish_color_" + name
|
||||
@@ -1087,20 +1089,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
varname = name
|
||||
# TODO: Check if the varname is allowable.
|
||||
command = "set -U " + varname
|
||||
if color:
|
||||
command += " " + color
|
||||
if background_color:
|
||||
command += " --background=" + background_color
|
||||
if bold:
|
||||
command += " --bold"
|
||||
if underline:
|
||||
command += " --underline"
|
||||
if italics:
|
||||
command += " --italics"
|
||||
if dim:
|
||||
command += " --dim"
|
||||
if reverse:
|
||||
command += " --reverse"
|
||||
command += " " + color
|
||||
|
||||
out, err = run_fish_cmd(command)
|
||||
return out
|
||||
@@ -1368,27 +1357,16 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
postvars = {}
|
||||
|
||||
if p == "/set_color/":
|
||||
what = postvars.get("what")
|
||||
color = postvars.get("color")
|
||||
background_color = postvars.get("background_color")
|
||||
bold = postvars.get("bold")
|
||||
italics = postvars.get("italics")
|
||||
reverse = postvars.get("reverse")
|
||||
dim = postvars.get("dim")
|
||||
underline = postvars.get("underline")
|
||||
print("# Colorscheme: " + postvars.get("theme"))
|
||||
for item in postvars.get("colors"):
|
||||
what = item.get("what")
|
||||
color = item.get("color")
|
||||
|
||||
if what:
|
||||
# Not sure why we get lists here?
|
||||
output = self.do_set_color_for_variable(
|
||||
what[0],
|
||||
color[0],
|
||||
background_color[0],
|
||||
parse_bool(bold[0]),
|
||||
parse_bool(underline[0]),
|
||||
parse_bool(italics[0]),
|
||||
parse_bool(dim[0]),
|
||||
parse_bool(reverse[0]),
|
||||
)
|
||||
if what:
|
||||
output = self.do_set_color_for_variable(
|
||||
what,
|
||||
color,
|
||||
)
|
||||
else:
|
||||
output = "Bad request"
|
||||
elif p == "/get_function/":
|
||||
|
||||
Reference in New Issue
Block a user