Fix __fish_list_current_token and friends for multiline commandlines

Some of these handled multiline prompts but not multiline command lines. We
first need to move the cursor to the end of the commandline, then we can
print a message.  Finally, we need to move the cursor back to where it was.
This commit is contained in:
Johannes Altmanninger 2024-04-11 12:34:58 +02:00
parent 8386088b3d
commit 9158395d10
6 changed files with 29 additions and 34 deletions

View File

@ -114,6 +114,7 @@ New or improved bindings
- The editor's cursor position is copied back to fish. This is currently supported for Vim and Kakoune. - The editor's cursor position is copied back to fish. This is currently supported for Vim and Kakoune.
- Cursor position synchronization is only supported for a set of known editors. This has been extended by also resolving aliases. For example use ``complete --wraps my-vim vim`` to synchronize cursors when `EDITOR=my-vim`. - Cursor position synchronization is only supported for a set of known editors. This has been extended by also resolving aliases. For example use ``complete --wraps my-vim vim`` to synchronize cursors when `EDITOR=my-vim`.
- ``backward-kill-path-component`` and friends now treat ``#`` as part of a path component (:issue:`10271`). - ``backward-kill-path-component`` and friends now treat ``#`` as part of a path component (:issue:`10271`).
- Bindings like :kbd:`alt-l` that print output in between prompts now work correctly with multiline commandlines.
- The ``E`` binding in vi mode now correctly handles the last character of the word, by jumping to the next word (:issue:`9700`). - The ``E`` binding in vi mode now correctly handles the last character of the word, by jumping to the next word (:issue:`9700`).
- If the terminal supports shifted key codes from the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/), ``shift-enter`` now inserts a newline instead of executing the command line. - If the terminal supports shifted key codes from the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/), ``shift-enter`` now inserts a newline instead of executing the command line.
- Vi mode has seen some improvements but continues to suffer from the lack of people working on it. - Vi mode has seen some improvements but continues to suffer from the lack of people working on it.

View File

@ -5,10 +5,9 @@ function __fish_anyeditor --description "Print a editor to use, or an error mess
else if set -q EDITOR else if set -q EDITOR
echo $EDITOR | read -at editor echo $EDITOR | read -at editor
else else
echo >&2 __fish_echo string join \n -- \
echo >&2 (_ 'External editor requested but $VISUAL or $EDITOR not set.') (_ 'External editor requested but $VISUAL or $EDITOR not set.') \
echo >&2 (_ 'Please set VISUAL or EDITOR to your preferred editor.') (_ 'Please set VISUAL or EDITOR to your preferred editor.')
commandline -f repaint
return 1 return 1
end end
string join \n $editor string join \n $editor

View File

@ -0,0 +1,8 @@
function __fish_echo --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
string >&2 repeat -N \n --count=(math (count (fish_prompt)) - 1)
string >&2 repeat -N \n --count=(math $line - 1)
commandline -f repaint
end

View File

@ -3,19 +3,16 @@
function __fish_list_current_token -d "List contents of token under the cursor if it is a directory, otherwise list the contents of the current directory" function __fish_list_current_token -d "List contents of token under the cursor if it is a directory, otherwise list the contents of the current directory"
set -l val (commandline -t | string replace -r '^~' "$HOME") set -l val (commandline -t | string replace -r '^~' "$HOME")
printf "\n" set -l cmd
if test -d $val if test -d $val
ls $val set cmd ls $val
else else
set -l dir (dirname -- $val) set -l dir (dirname -- $val)
if test $dir != . -a -d $dir if test $dir != . -a -d $dir
ls $dir set cmd ls $dir
else else
ls set cmd ls
end end
end end
__fish_echo $cmd
string repeat -N \n --count=(math (count (fish_prompt)) - 1)
commandline -f repaint
end end

View File

@ -6,7 +6,6 @@ function __fish_whatis_current_token -d "Show man page entries or function descr
test -n "$token" test -n "$token"
or return or return
printf "\n"
set -l desc "$token: nothing appropriate." set -l desc "$token: nothing appropriate."
set -l tokentype (type --type $token 2>/dev/null) set -l tokentype (type --type $token 2>/dev/null)
@ -26,9 +25,5 @@ function __fish_whatis_current_token -d "Show man page entries or function descr
and set desc $tmpdesc and set desc $tmpdesc
end end
printf "%s\n" $desc __fish_echo string join \n -- $desc
string repeat -N \n --count=(math (count (fish_prompt)) - 1)
commandline -f repaint
end end

View File

@ -27,30 +27,25 @@ function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name si
set -l max_cmd_len 32 set -l max_cmd_len 32
set cmd_line (string shorten -m$max_cmd_len -- $cmd_line) set cmd_line (string shorten -m$max_cmd_len -- $cmd_line)
if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED set -l message
# Add a newline *before* our message so we get the message after the commandline.
echo >&2
end
switch $signal_or_end_name switch $signal_or_end_name
case STOPPED case STOPPED
printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line set message (printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line)
case ENDED case ENDED
printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line set message (printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line)
case 'SIG*' case 'SIG*'
if test -n "$proc_pid" if test -n "$proc_pid"
printf ( _ "fish: Process %s, '%s' from job %s, '%s' terminated by signal %s (%s)\n" ) \ set message (printf ( _ "fish: Process %s, '%s' from job %s, '%s' terminated by signal %s (%s)\n" ) \
$proc_pid $proc_name $job_id $cmd_line $signal_or_end_name $signal_desc $proc_pid $proc_name $job_id $cmd_line $signal_or_end_name $signal_desc)
else else
printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \ set message (printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \
$job_id $cmd_line $signal_or_end_name $signal_desc $job_id $cmd_line $signal_or_end_name $signal_desc)
end end
end >&2 end
if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED
# We want one newline per line in the prompt after the first. __fish_echo string join \n -- $message
# To ensure that, don't let `string repeat` add a newline. See #9044. else
string repeat -N \n --count=(math (count (fish_prompt)) - 1) >&2 string join >&2 \n -- $message
commandline -f repaint
end end
end end