mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-01 12:23:17 +08: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:
parent
32826d3596
commit
2aec6e5814
|
@ -143,6 +143,10 @@ controllers.controller("colorsController", function($scope, $http) {
|
|||
"fish_pager_color_progress"
|
||||
];
|
||||
var remaining = settingNames.length;
|
||||
postdata = {
|
||||
"theme" : $scope.selectedColorScheme["name"],
|
||||
"colors": [],
|
||||
}
|
||||
for (name of settingNames) {
|
||||
var selected;
|
||||
// Skip colors undefined in the current theme
|
||||
|
@ -157,17 +161,16 @@ controllers.controller("colorsController", function($scope, $http) {
|
|||
} else {
|
||||
selected = $scope.selectedColorScheme[name];
|
||||
}
|
||||
var postData = "what=" + name + "&color=" + selected + "&background_color=&bold=&underline=&dim=&reverse=&italics=";
|
||||
$http.post("set_color/", postData, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).then(function(arg) {
|
||||
if (arg.status == 200) {
|
||||
remaining -= 1;
|
||||
if (remaining == 0) {
|
||||
/* All styles set! */
|
||||
$scope.saveThemeButtonTitle = "Theme Set!";
|
||||
}
|
||||
}
|
||||
})
|
||||
postdata.colors.push({
|
||||
"what" : name,
|
||||
"color" : selected,
|
||||
});
|
||||
}
|
||||
$http.post("set_color/", postdata, { headers: {'Content-Type': 'application/json'} }).then(function(arg) {
|
||||
if (arg.status == 200) {
|
||||
$scope.saveThemeButtonTitle = "Theme Set!";
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
$scope.getCurrentTheme();
|
||||
|
|
|
@ -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/":
|
||||
|
|
Loading…
Reference in New Issue
Block a user