From: Bart Schaefer <schaefer@brasslantern.com>
To: OG Code Poet <ogcodepoet@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
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 [thread overview]
Message-ID: <CAH+w=7ZDaLHEP6qa6eV0oSWkJAhj-TbY+sZZM+rUBrkgGoBF-w@mail.gmail.com> (raw)
In-Reply-To: <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@gmail.com> 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.)
next prev parent reply other threads:[~2022-12-30 17:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-30 5:37 OG Code Poet
2022-12-30 8:58 ` Mikael Magnusson
2022-12-30 17:56 ` Bart Schaefer [this message]
2022-12-31 3:52 ` OG Code Poet
2022-12-31 5:20 ` Bart Schaefer
2022-12-31 5:44 ` OG Code Poet
2022-12-31 13:13 ` Oliver Kiddle
2023-01-01 0:10 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7ZDaLHEP6qa6eV0oSWkJAhj-TbY+sZZM+rUBrkgGoBF-w@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=ogcodepoet@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).