mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 14:28:45 +08:00
Webconfig: Read metadata from themes
This readds the preferred background and url, all read from "# url:" and "# preferred_background:" comments in the .theme file.
This commit is contained in:
parent
f301639d07
commit
51a55b25dc
|
@ -81,14 +81,30 @@ controllers.controller("colorsController", function($scope, $http) {
|
|||
/* Array of FishColorSchemes */
|
||||
$scope.colorSchemes = [];
|
||||
|
||||
isValidColor = function(col) {
|
||||
// Check if preferred_background is actually a valid color
|
||||
var s = new Option().style;
|
||||
s.color = col;
|
||||
return !!s.color;
|
||||
}
|
||||
|
||||
$scope.getThemes = function() {
|
||||
$http.get("colors/").then(function(arg) {
|
||||
for (var scheme of arg.data) {
|
||||
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
||||
currentScheme["name"] = scheme["theme"];
|
||||
var data = scheme["colors"];
|
||||
if (scheme["preferred_background"]) {
|
||||
if (isValidColor(scheme["preferred_background"])) {
|
||||
currentScheme["preferred_background"] = scheme["preferred_background"];
|
||||
}
|
||||
}
|
||||
if (scheme["url"]) currentScheme["url"] = scheme["url"];
|
||||
|
||||
for (var i in data) {
|
||||
currentScheme[data[i].name] = data[i].color;
|
||||
if (isValidColor(data[i].color)) {
|
||||
currentScheme[data[i].name] = data[i].color;
|
||||
}
|
||||
}
|
||||
$scope.colorSchemes.push(currentScheme);
|
||||
}
|
||||
|
|
|
@ -941,7 +941,23 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
else:
|
||||
with open(path) as f:
|
||||
out = f.read()
|
||||
extrainfo = {}
|
||||
for line in out.split("\n"):
|
||||
# Ignore empty lines
|
||||
if not line: continue
|
||||
# Lines starting with "#" can contain metadata.
|
||||
if line.startswith("#"):
|
||||
if not ":" in line: continue
|
||||
key, value = line.split(":", maxsplit=1)
|
||||
key = key.strip("# '")
|
||||
value = value.strip(" '\"")
|
||||
# Only use keys we know
|
||||
if not key in ["name", "preferred_background", "url"]: continue
|
||||
if key == "preferred_background":
|
||||
if not value in named_colors and not value.startswith("#"):
|
||||
value = "#" + value
|
||||
extrainfo[key] = value
|
||||
|
||||
|
||||
for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
|
||||
color_name, color_value = [x.strip() for x in match.group(1, 2)]
|
||||
|
@ -960,7 +976,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
color_desc = descriptions.get(color_name, "")
|
||||
result.append([color_name, color_desc, parse_color("")])
|
||||
|
||||
return result
|
||||
return result, extrainfo
|
||||
|
||||
def do_get_functions(self):
|
||||
out, err = run_fish_cmd("functions")
|
||||
|
@ -1297,15 +1313,19 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
# Construct our colorschemes.
|
||||
# Add the current scheme first, then the default.
|
||||
# The rest in alphabetical order.
|
||||
output = [{ "theme": "Current", "colors": self.do_get_colors()},
|
||||
{ "theme": "fish default", "colors": self.do_get_colors("themes/fish default.theme")}]
|
||||
curcolors, curinfo = self.do_get_colors()
|
||||
defcolors, definfo = self.do_get_colors("themes/fish default.theme")
|
||||
curinfo.update({ "theme": "Current", "colors": curcolors})
|
||||
definfo.update({ "theme": "fish default", "colors": defcolors})
|
||||
output = [curinfo, definfo]
|
||||
paths = sorted(glob.iglob("themes/*.theme"), key=str.casefold)
|
||||
for p in paths:
|
||||
# Strip ".theme" suffix and path
|
||||
theme = os.path.basename(p)[:-6]
|
||||
if any(theme == d["theme"] for d in output): continue
|
||||
out = self.do_get_colors(p)
|
||||
output.append({ "theme": theme, "colors": out})
|
||||
out, outinfo = self.do_get_colors(p)
|
||||
outinfo.update({ "theme": theme, "colors": out })
|
||||
output.append(outinfo)
|
||||
print(len(output))
|
||||
elif p == "/functions/":
|
||||
output = self.do_get_functions()
|
||||
|
|
Loading…
Reference in New Issue
Block a user