reset_abandoning_line: actually clear line on first prompt

Frequently when I launch a new shell and type away, my input is
echoed in the terminal before fish gets a chance to set shell modes
(turn off ECHO and put the terminal into non-canonical mode).

This means that fish assumption about the cursor x=0 is wrong, which
causes the prompt (here '$ ') to be draw at the wrong place, making
it look like this:

	ececho hello

This seems to have been introduced in 4.1.0 in a0e687965e (Fix
unsaved screen modification, 2025-01-14). Not sure how it wasn't a
problem before.

Fix this by clearing to the beginning of the line after turning off
ECHO but before we draw anything to the screen.

This turns this comment in the patch context into a true statement:

> This means that `printf %s foo; fish` will overwrite the `foo`

Note that this currently applies per-reader, so builtin "read" will
also clear the line before doing anything.
We could potentially change this in future, if we both
1. query the cursor x before we output anything
2. refactor the screen module to properly deal with x>0 states.

But even if we did that, it wouldn't change the fact that we want
to force x=0 if the cursor has only been moved due to ECHO, so I'm
not sure.
This commit is contained in:
Johannes Altmanninger
2025-11-11 18:09:29 +01:00
parent b48106a741
commit 289057f981
5 changed files with 54 additions and 11 deletions

View File

@@ -0,0 +1,15 @@
#RUN: %fish %s
#REQUIRES: command -v tmux
tmux_wait=false \
isolated-tmux-start -C '
function fish_prompt
command printf "%% "
end
'
isolated-tmux send-keys 'echo hello'
tmux-sleep
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: % echo hello