Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Read a line from user without clearing screen below the prompt while allowing user to use arrow keys to make edits in middle of line
- X-seq: zsh-workers 51261
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: OG Code Poet <ogcodepoet@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Read a line from user without clearing screen below the prompt while allowing user to use arrow keys to make edits in middle of line
- Date: Fri, 30 Dec 2022 09:56:21 -0800
- Archived-at: <https://zsh.org/workers/51261>
- In-reply-to: <CADmFDtUiRpYTYh21-aeE_UuSAHqG=c2vcRT0oSND+i9ehu4SOA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CADmFDtUiRpYTYh21-aeE_UuSAHqG=c2vcRT0oSND+i9ehu4SOA@mail.gmail.com>
(Leaving this on -workers because of the possible bug mentioned at the end.)
On Thu, Dec 29, 2022 at 9:38 PM OG Code Poet <ogcodepoet@xxxxxxxxx> wrote:
>
> Using Bash ``tput cup 0 0; read -e -p "Enter input: " userinput`` works well for getting a line of user input:
>
> * It does not clear screen below the prompt
> * It allows user to use arrow keys to go to middle of line and edit a mistake they might have made while typing
Bash is invoking the GNU "readline" library for the "read" builtin.
Unlike ZLE, which despite having "line" in its name attempts to be a
reasonable multi-line editor, readline is designed to do exactly what
its name says, so it doesn't do any other screen prep.
> How can this be achieved in zsh?
Closest I can come up with is this:
vared-finish() { tput rc }
zle -N vared-finish
tput sc
vared -f vared-finish -c -p "%{$(tput cup 0 0)%}Enter input: " userinput
However, this is not entirely satisfactory because the finish widget
is not invoked if this is interrupted by ^C or ^G (send-break), and
vared then clears the screen before exiting. This is possibly a bug?
Shouldn't the finish widget(s) always be run when the line editor
exits, even if it exits "abnormally"? (This affects the PS1 ZLE as
well.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author