zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: OG Code Poet <ogcodepoet@gmail.com>
Cc: 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:58:33 +0100	[thread overview]
Message-ID: <CAHYJk3SAUQEthcuhFHt8STLRYnvMkFcyskpmaG5VmMpoYg6=FQ@mail.gmail.com> (raw)
In-Reply-To: <CADmFDtUiRpYTYh21-aeE_UuSAHqG=c2vcRT0oSND+i9ehu4SOA@mail.gmail.com>

On 12/30/22, 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
>
> How can this be achieved in zsh? I have tried two techniques; either it
> clears screen below prompt or it does not allow using arrow to go back to
> middle of line to edit it.
>
> 1. Using ``vared``:
> ```
> tput cup 0 0; userinput=""; vared -p "Enter input: " userinput
> ```
> ``vared`` seems to clear screen below the prompt, so this clears the entire
> screen before showing the prompt.
>
> 2. Using ``read``:
>
> ```
> tput cup 0 0; printf "Enter input: "; read -r userinput
> ```
> This does not clear the screen below the prompt, but does not allow using
> arrow keys to go to middle of the line and make an edit ("delete" key
> works, but is too much to ask users to delete and retype everything from
> the point of typo).
>
> Is there a way out? Perhaps it could be possible to trick vared to believe
> there are no lines below, so it clears just 1 line (the line of prompt). If
> it is not possible in zsh, I am open to an external POSIX way of getting
> user input on first line of the screen.
>
> P.S. Also posted in unix.stackexchange.com:
> https://unix.stackexchange.com/q/730022/456507

Without more context this sounds like a very weird request, surely
printing stuff at 0,0 will just overlap whatever existing text was
there, resulting in a corrupted screen output? Perhaps you will have
better luck switching to the alternate screen while prompting for the
string, and then switching back, in effect giving you the appearance
of a full screen program (more likely to direct the user's attention
to the top of the terminal). (enable with echo -n '\e[?47h' and
disable with echo -n '\e[?47l')

PS
this is probably more of a zsh-users question than zsh-workers

-- 
Mikael Magnusson


  reply	other threads:[~2022-12-30  8:59 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 [this message]
2022-12-30 17:56 ` Bart Schaefer
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='CAHYJk3SAUQEthcuhFHt8STLRYnvMkFcyskpmaG5VmMpoYg6=FQ@mail.gmail.com' \
    --to=mikachu@gmail.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).