__fish_echo: fully overwrite lines

With upcoming multi-line autosuggestions, when I run

	$ function foo
	    true
	  end

and type "function", then I'll get a suggestion for the above command.
Now if press "alt-w", it will echo "function - create a function"
and rewdraw the prompt below.  But the previous autosuggestion is
not cleared, so it will look weird like:

	johannes@abc ~/g/fish-shell> function foo
	function - create a function     true

Let's erase these lines before writing them.

There's an issue remaining: the first line of the autosuggestion
(i.e. "foo") is not erased.  Fortunately this is less annoying,
but it shows that __fish_echo needs more support from core.
This commit is contained in:
Johannes Altmanninger
2025-09-17 11:33:43 +02:00
parent c0c7b364fc
commit 1fdf37cc4a

View File

@@ -1,7 +1,15 @@
function __fish_echo --description 'run the given command after the current commandline and redraw the prompt'
set -l erase_line "$(
if status test-feature ignore-terminfo
echo \e\[K
else if type -q tput
tput el
end
)"
function __fish_echo --inherit-variable erase_line --description 'run the given command after the current commandline and redraw the prompt'
set -l line (commandline --line)
string >&2 repeat -N \n --count=(math (commandline | count) - $line + 1)
$argv >&2
printf %s\n $erase_line($argv) >&2
string >&2 repeat -N \n --count=(math (count (fish_prompt)) - 1)
string >&2 repeat -N \n --count=(math $line - 1)
commandline -f repaint