From b28a18be73567a53807252f21f1fca365cd8de92 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 9 Apr 2022 22:06:06 +0200 Subject: [PATCH] Simplify cursor movement for multi-line prompts before repainting We have some key bindings that print directly to the terminal while the user is still typing the command line. Thereafter, we redraw the command line, so the user can resume typing. To redraw a multiline command line, we first erase several lines above the cursor. To not erase the key bindings' output, we move the cursor down that many lines. Simplify the logic; no functional change. --- share/functions/__fish_list_current_token.fish | 7 +------ share/functions/__fish_whatis_current_token.fish | 10 +--------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/share/functions/__fish_list_current_token.fish b/share/functions/__fish_list_current_token.fish index 0bbd90665..b6c004b19 100644 --- a/share/functions/__fish_list_current_token.fish +++ b/share/functions/__fish_list_current_token.fish @@ -15,12 +15,7 @@ function __fish_list_current_token -d "List contents of token under the cursor i end end - set -l line_count (count (fish_prompt)) - if test $line_count -gt 1 - for x in (seq 2 $line_count) - printf "\n" - end - end + string repeat \n --count=(math (count (fish_prompt)) - 1) commandline -f repaint end diff --git a/share/functions/__fish_whatis_current_token.fish b/share/functions/__fish_whatis_current_token.fish index b097fe788..390ec98cb 100644 --- a/share/functions/__fish_whatis_current_token.fish +++ b/share/functions/__fish_whatis_current_token.fish @@ -28,15 +28,7 @@ function __fish_whatis_current_token -d "Show man page entries or function descr printf "%s\n" $desc - set -l line_count (count (fish_prompt)) - # Ensure line_count is greater than one to accomodate different - # versions of the `seq` command, some of which print the sequence in - # reverse order when the second argument is smaller than the first - if test $line_count -gt 1 - for x in (seq 2 $line_count) - printf "\n" - end - end + string repeat \n --count=(math (count (fish_prompt)) - 1) commandline -f repaint end