mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-08 11:29:03 +08:00
Webconfig: Read colorschemes from .theme files
This commit is contained in:
parent
8091303659
commit
0e3d7de889
|
@ -79,34 +79,20 @@ controllers.controller("colorsController", function($scope, $http) {
|
||||||
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', '#'+nord.nord0, 'black'];
|
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', '#'+nord.nord0, 'black'];
|
||||||
|
|
||||||
/* Array of FishColorSchemes */
|
/* Array of FishColorSchemes */
|
||||||
$scope.colorSchemes = [
|
$scope.colorSchemes = [];
|
||||||
color_scheme_fish_default,
|
|
||||||
color_scheme_ayu_light,
|
|
||||||
color_scheme_ayu_dark,
|
|
||||||
color_scheme_ayu_mirage,
|
|
||||||
color_scheme_solarized_light,
|
|
||||||
color_scheme_solarized_dark,
|
|
||||||
color_scheme_tomorrow,
|
|
||||||
color_scheme_tomorrow_night,
|
|
||||||
color_scheme_tomorrow_night_bright,
|
|
||||||
color_scheme_nord,
|
|
||||||
color_scheme_base16_default_dark,
|
|
||||||
color_scheme_base16_default_light,
|
|
||||||
color_scheme_base16_eighties
|
|
||||||
];
|
|
||||||
for (var i=0; i < additional_color_schemes.length; i++)
|
|
||||||
$scope.colorSchemes.push(additional_color_schemes[i])
|
|
||||||
|
|
||||||
|
$scope.getThemes = function() {
|
||||||
$scope.getCurrentTheme = function() {
|
|
||||||
$http.get("colors/").then(function(arg) {
|
$http.get("colors/").then(function(arg) {
|
||||||
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
for (var scheme of arg.data) {
|
||||||
var data = arg.data
|
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
||||||
for (var i in data) {
|
currentScheme["name"] = scheme["theme"];
|
||||||
currentScheme[data[i].name] = data[i].color;
|
var data = scheme["colors"];
|
||||||
|
for (var i in data) {
|
||||||
|
currentScheme[data[i].name] = data[i].color;
|
||||||
|
}
|
||||||
|
$scope.colorSchemes.push(currentScheme);
|
||||||
}
|
}
|
||||||
$scope.colorSchemes.splice(0, 0, currentScheme);
|
$scope.changeSelectedColorScheme($scope.colorSchemes[0]);
|
||||||
$scope.changeSelectedColorScheme(currentScheme);
|
|
||||||
})};
|
})};
|
||||||
|
|
||||||
$scope.saveThemeButtonTitle = "Set Theme";
|
$scope.saveThemeButtonTitle = "Set Theme";
|
||||||
|
@ -173,7 +159,7 @@ controllers.controller("colorsController", function($scope, $http) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getCurrentTheme();
|
$scope.getThemes();
|
||||||
});
|
});
|
||||||
|
|
||||||
controllers.controller("promptController", function($scope, $http) {
|
controllers.controller("promptController", function($scope, $http) {
|
||||||
|
|
|
@ -880,7 +880,8 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
def write_to_wfile(self, txt):
|
def write_to_wfile(self, txt):
|
||||||
self.wfile.write(txt.encode("utf-8"))
|
self.wfile.write(txt.encode("utf-8"))
|
||||||
|
|
||||||
def do_get_colors(self):
|
def do_get_colors(self, path=None):
|
||||||
|
""" Read the colors from a .theme file or the current shell config (if no path has been given) """
|
||||||
# Looks for fish_color_*.
|
# Looks for fish_color_*.
|
||||||
# Returns an array of lists [color_name, color_description, color_value]
|
# Returns an array of lists [color_name, color_description, color_value]
|
||||||
result = []
|
result = []
|
||||||
|
@ -934,7 +935,12 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
"cancel": "The ^C cancel indicator",
|
"cancel": "The ^C cancel indicator",
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err = run_fish_cmd("set -L")
|
# If we don't have a path, we get the current theme.
|
||||||
|
if not path:
|
||||||
|
out, err = run_fish_cmd("set -L")
|
||||||
|
else:
|
||||||
|
with open(path) as f:
|
||||||
|
out = f.read()
|
||||||
for line in out.split("\n"):
|
for line in out.split("\n"):
|
||||||
|
|
||||||
for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
|
for match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
|
||||||
|
@ -1288,7 +1294,19 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
self.path = p
|
self.path = p
|
||||||
|
|
||||||
if p == "/colors/":
|
if p == "/colors/":
|
||||||
output = self.do_get_colors()
|
# 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")}]
|
||||||
|
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})
|
||||||
|
print(len(output))
|
||||||
elif p == "/functions/":
|
elif p == "/functions/":
|
||||||
output = self.do_get_functions()
|
output = self.do_get_functions()
|
||||||
elif p == "/variables/":
|
elif p == "/variables/":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user