webconfig: Handle right prompt

This gets fish to print the right prompt of any sample if it has any,
and then shows it separately.

If there is a right prompt, it will also save it. If not, it will *not* overwrite an existing right prompt.
This commit is contained in:
Fabian Homborg 2021-04-14 19:25:48 +02:00
parent 2fff12104d
commit 4355636386
4 changed files with 181 additions and 168 deletions

View file

@ -198,6 +198,7 @@ controllers.controller("promptController", function($scope, $http) {
// Update attributes of current prompt and select it
$scope.samplePrompts[0].demo = selectedPrompt.demo;
$scope.samplePrompts[0].right = selectedPrompt.right;
$scope.samplePrompts[0].function = selectedPrompt.function;
$scope.samplePrompts[0].font_size = selectedPrompt.font_size;
$scope.selectedPrompt = $scope.samplePrompts[0];

View file

@ -2,7 +2,10 @@
<!-- The first 'sample' prompt is the current one; the remainders are samples. This ought to be cleaned up. -->
<div class="current_prompt" style="min-height: 7.5em;" ng-style="{'background-color': terminalBackgroundColor}">
<div class="prompt_demo_choice_label" style="color: #FFF;">{{ selectedPrompt.name }}</div>
<div ng-bind-html='selectedPrompt.demo | to_trusted' class="prompt_demo unbordered"></div>
<div style='display: flex'>
<div ng-bind-html='selectedPrompt.demo | to_trusted' style='flex-grow: 1' class="prompt_demo unbordered"></div>
<div ng-if='selectedPrompt.right' title="right prompt for {{selectedPrompt.name }}" ng-bind-html='selectedPrompt.right | to_trusted' class="prompt_demo unbordered" ng-click="selectPrompt(prompt)"></div>
</div>
<div style="position: absolute; right: 5px; bottom: 5px; color:">
<span class="save_button"
ng-show="showSaveButton"
@ -15,7 +18,11 @@
<div class="prompt_choices_list">
<div ng-repeat="prompt in samplePrompts">
<div class="prompt_demo_choice_label">{{ prompt.name }}</div>
<div ng-bind-html='prompt.demo | to_trusted' class="prompt_demo" ng-click="selectPrompt(prompt)"></div>
<div ng-if='prompt.right' style='display: flex;'>
<div ng-bind-html='prompt.demo | to_trusted' class="prompt_demo" style='flex-grow: 1' ng-click="selectPrompt(prompt)"></div>
<div ng-if='prompt.right' title="right prompt for {{prompt.name}}" ng-bind-html='prompt.right | to_trusted' class="prompt_demo" ng-click="selectPrompt(prompt)"></div>
</div>
<div ng-if='!prompt.right' ng-bind-html='prompt.demo | to_trusted' class="prompt_demo" ng-click="selectPrompt(prompt)"></div>
</div>
</div>
</div>

View file

@ -18,6 +18,7 @@ function fish_prompt
end
echo -n (set_color red)''(set_color yellow)''(set_color green)' '
set_color normal
end
# And now define the right prompt so that it's brought along
function fish_right_prompt
@ -181,4 +182,3 @@ function fish_prompt
set_color normal
end
end

View file

@ -1119,7 +1119,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return True
def do_set_prompt_function(self, prompt_func):
cmd = prompt_func + "\n" + "funcsave fish_prompt"
cmd = "functions -e fish_right_prompt; " + prompt_func + "\n" + "funcsave fish_prompt && funcsave fish_right_prompt 2>/dev/null"
out, err = run_fish_cmd(cmd)
return len(err) == 0
@ -1128,11 +1128,16 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
cmd = prompt_function_text + '\n builtin cd "' + initial_wd + '" \n false \n fish_prompt\n'
prompt_demo_ansi, err = run_fish_cmd(cmd)
prompt_demo_html = ansi_to_html(prompt_demo_ansi)
prompt_demo_font_size = self.font_size_for_ansi_prompt(prompt_demo_ansi)
right_demo_ansi, err = run_fish_cmd(
"functions -e fish_right_prompt; " + prompt_function_text + '\n builtin cd "' + initial_wd + '" \n false \n functions -q fish_right_prompt && fish_right_prompt\n'
)
right_demo_html = ansi_to_html(right_demo_ansi)
prompt_demo_font_size = self.font_size_for_ansi_prompt(prompt_demo_ansi + right_demo_ansi)
result = {
"function": prompt_function_text,
"demo": prompt_demo_html,
"font_size": prompt_demo_font_size,
"right": right_demo_html,
}
if extras_dict:
result.update(extras_dict)
@ -1141,7 +1146,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_get_current_prompt(self):
# Return the current prompt. We run 'false' to demonstrate how the
# prompt shows the command status (#1624).
prompt_func, err = run_fish_cmd("functions fish_prompt")
prompt_func, err = run_fish_cmd("functions fish_prompt; functions fish_right_prompt")
result = self.do_get_prompt(
prompt_func.strip(),
{"name": "Current"},