From 04f518082c2fc540f55e458acd8b0cb0abe5e4a6 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Sun, 13 Oct 2013 18:36:46 +0530 Subject: [PATCH] Initial implementation of bindings tab --- share/tools/web_config/fishconfig.css | 4 +-- share/tools/web_config/fishconfig.js | 48 +++++++++++++++++++++++++-- share/tools/web_config/index.html | 1 + share/tools/web_config/webconfig.py | 33 +++++++++++++++++- 4 files changed, 81 insertions(+), 5 deletions(-) diff --git a/share/tools/web_config/fishconfig.css b/share/tools/web_config/fishconfig.css index 550c89e1d..2553d0aa7 100644 --- a/share/tools/web_config/fishconfig.css +++ b/share/tools/web_config/fishconfig.css @@ -31,7 +31,7 @@ body { padding-top: 15px; font-size: 17pt; text-align: center; - width: 20%; + width: 15%; background-color: #292929; cursor: pointer; } @@ -444,4 +444,4 @@ img.delete_icon { height: 16px; vertical-align: text-top; margin-left: 10px; -}; \ No newline at end of file +}; diff --git a/share/tools/web_config/fishconfig.js b/share/tools/web_config/fishconfig.js index b2abddeed..64ac85368 100644 --- a/share/tools/web_config/fishconfig.js +++ b/share/tools/web_config/fishconfig.js @@ -40,6 +40,10 @@ fishconfig.config( controller: "historyController", templateUrl: "partials/history.html" }) + .when("/bindings", { + controller: "bindingsController", + templateUrl: "partials/bindings.html" + }) .otherwise({ redirectTo: "/colors" }) @@ -327,9 +331,39 @@ fishconfig.controller("colorsController", function($scope, $http) { return result; } + /* Given an RGB color as a hex string, like FF0033, convert to HSL, apply the function to adjust its lightness, then return the new color as an RGB string */ + $scope.adjust_lightness = function(color_str, func) { + /* Hack to handle for example F00 */ + if (color_str.length == 3) { + color_str = color_str[0] + color_str[0] + color_str[1] + color_str[1] + color_str[2] + color_str[2] + } + + /* More hacks */ + if (color_str == 'black') color_str = '000000'; + if (color_str == 'white') color_str = 'FFFFFF'; + + + rgb = parseInt(color_str, 16) + r = (rgb >> 16) & 0xFF + g = (rgb >> 8) & 0xFF + b = (rgb >> 0) & 0xFF + + hsl = rgb_to_hsl(r, g, b) + new_lightness = func(hsl[2]) + function to_int_str(val) { + str = Math.round(val).toString(16) + while (str.length < 2) + str = '0' + str + return str + } + + new_rgb = hsl_to_rgb(hsl[0], hsl[1], new_lightness) + return to_int_str(new_rgb[0]) + to_int_str(new_rgb[1]) + to_int_str(new_rgb[2]) + } + /* Given a color, compute a "border color" for it that can show it selected */ $scope.border_color_for_color = function (color_str) { - return adjust_lightness(color_str, function(lightness){ + return $scope.adjust_lightness(color_str, function(lightness){ var adjust = .5 var new_lightness = lightness + adjust if (new_lightness > 1.0 || new_lightness < 0.0) { @@ -349,7 +383,7 @@ fishconfig.controller("colorsController", function($scope, $http) { } return new_lightness } - return adjust_lightness(color_str, compute_constrast); + return $scope.adjust_lightness(color_str, compute_constrast); } $scope.changeSelectedColorScheme= function(newScheme) { @@ -767,3 +801,13 @@ fishconfig.controller("historyController", function($scope, $http, $timeout) { $scope.fetchHistory(); }); + +fishconfig.controller("bindingsController", function($scope, $http) { + $scope.bindings = []; + $scope.fetchBindings = function() { + $http.get("/bindings/").success(function(data, status, headers, config) { + $scope.bindings = data; + })}; + + $scope.fetchBindings(); +}); diff --git a/share/tools/web_config/index.html b/share/tools/web_config/index.html index 9e644fbc3..8b16ffde4 100644 --- a/share/tools/web_config/index.html +++ b/share/tools/web_config/index.html @@ -101,6 +101,7 @@ function interpret_color(str) {
functions
variables
history
+
bindings
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index e3c1dbcb6..6d21839fb 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -250,6 +250,17 @@ class FishVar: if self.exported: flags.append('exported') return {"name": self.name, "value": self.value, "Flags": ', '.join(flags)} +class FishBinding: + """A class that represents keyboard binding """ + + def __init__(self, command, binding, description=None): + self.command = command + self.binding = binding + self.description = description + + def get_json_obj(self): + return {"command" : self.command, "binding": self.binding, "description": self.description } + class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def write_to_wfile(self, txt): @@ -359,6 +370,25 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): return [vars[key].get_json_obj() for key in sorted(vars.keys(), key=str.lower)] + def do_get_bindings(self): + out, err = run_fish_cmd('fish -i -c "functions --erase fish_prompt; bind"') + #import ipdb; ipdb.set_trace() + # Put all the bindings into a dictionary + bindings = [] + for line in out.split('\n'): + comps = line.split(' ', 2) + if len(comps) < 3: + continue + if comps[1] == '-k': + key_name, command = comps[2].split(' ', 2) + fish_binding = FishBinding(command=command, binding=key_name) + else: + fish_binding = FishBinding(command=comps[2], binding=comps[1]) + + bindings.append(fish_binding) + + return [ binding.get_json_obj() for binding in bindings ] + def do_get_history(self): # Use \x1e ("record separator") to distinguish between history items. The first # backslash is so Python passes one backslash to fish @@ -367,7 +397,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): if result: result.pop() # Trim off the trailing element return result - def do_get_color_for_variable(self, name): "Return the color with the given name, or the empty string if there is none" out, err = run_fish_cmd("echo -n $" + name) @@ -498,6 +527,8 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): elif re.match(r"/color/(\w+)/", p): name = re.match(r"/color/(\w+)/", p).group(1) output = self.do_get_color_for_variable(name) + elif p == '/bindings/': + output = self.do_get_bindings() else: return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)