zsh-workers
 help / color / mirror / code / Atom feed
* 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
@ 2022-12-30  5:37 OG Code Poet
  2022-12-30  8:58 ` Mikael Magnusson
  2022-12-30 17:56 ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: OG Code Poet @ 2022-12-30  5:37 UTC (permalink / raw)
  To: zsh-workers; +Cc: OG Code Poet

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1671 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-01  0:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30  5:37 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 OG Code Poet
2022-12-30  8:58 ` Mikael Magnusson
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

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).