Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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



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.comhttps://unix.stackexchange.com/q/730022/456507


Messages sorted by: Reverse Date, Date, Thread, Author