mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-12 07:57:22 +00:00
Initial implementation of bindings tab
This commit is contained in:
parent
26926551cf
commit
04f518082c
4 changed files with 81 additions and 5 deletions
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -101,6 +101,7 @@ function interpret_color(str) {
|
|||
<div ng-class="tabCssClass('functions')" id="tab_functions" ng-click="changeView('functions')">functions</div>
|
||||
<div ng-class="tabCssClass('variables')" id="tab_variables" ng-click="changeView('variables')">variables</div>
|
||||
<div ng-class="tabCssClass('history')" id="tab_history" ng-click="changeView('history')">history</div>
|
||||
<div ng-class="tabCssClass('bindings')" id="tab_bindings" ng-click="changeView('bindings')">bindings</div>
|
||||
</div>
|
||||
<div id="tab_contents">
|
||||
<ng-view></ng-view>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue