mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Webconfig: Read colorschemes from .theme files
This commit is contained in:
parent
8091303659
commit
0e3d7de889
2 changed files with 33 additions and 29 deletions
|
@ -79,34 +79,20 @@ controllers.controller("colorsController", function($scope, $http) {
|
|||
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', '#'+nord.nord0, 'black'];
|
||||
|
||||
/* Array of FishColorSchemes */
|
||||
$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.colorSchemes = [];
|
||||
|
||||
|
||||
$scope.getCurrentTheme = function() {
|
||||
$scope.getThemes = function() {
|
||||
$http.get("colors/").then(function(arg) {
|
||||
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
||||
var data = arg.data
|
||||
for (var i in data) {
|
||||
currentScheme[data[i].name] = data[i].color;
|
||||
for (var scheme of arg.data) {
|
||||
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
||||
currentScheme["name"] = scheme["theme"];
|
||||
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(currentScheme);
|
||||
$scope.changeSelectedColorScheme($scope.colorSchemes[0]);
|
||||
})};
|
||||
|
||||
$scope.saveThemeButtonTitle = "Set Theme";
|
||||
|
@ -173,7 +159,7 @@ controllers.controller("colorsController", function($scope, $http) {
|
|||
})
|
||||
};
|
||||
|
||||
$scope.getCurrentTheme();
|
||||
$scope.getThemes();
|
||||
});
|
||||
|
||||
controllers.controller("promptController", function($scope, $http) {
|
||||
|
|
|
@ -880,7 +880,8 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
def write_to_wfile(self, txt):
|
||||
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_*.
|
||||
# Returns an array of lists [color_name, color_description, color_value]
|
||||
result = []
|
||||
|
@ -934,7 +935,12 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
"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 match in re.finditer(r"^fish_color_(\S+) ?(.*)", line):
|
||||
|
@ -1288,7 +1294,19 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
self.path = p
|
||||
|
||||
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/":
|
||||
output = self.do_get_functions()
|
||||
elif p == "/variables/":
|
||||
|
|
Loading…
Reference in a new issue