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



I had tried tput cup $LINES $((COLUMNS-1)) and tput cup $LINES $COLUMNS. Vared seems to clear the entire line of cursor, not just from cursor position to the end of line. Not sure if this has something to do with xterm-256color and tmux-256color, unlike the description of tput el "clear to end of line". On all the terminals I have tested this on, they clear from beginning of current line to the end. My machine is: Apple Silicon macOS 13.1. Did that really work on your machine?

On Fri, Dec 30, 2022 at 9:20 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Fri, Dec 30, 2022 at 7:52 PM OG Code Poet <ogcodepoet@xxxxxxxxx> wrote:
>
> Here's some more context.

So ... vared sends the clear-to-end-of-screen before printing the
prompt, then starts ZLE and clears again after ZLE exits.  This means
your job, in creating a workaround, is to move the cursor to the lower
right corner of the screen before calling vared, move it to the
desired position before printing the prompt, and move back to the
lower right again before ending ZLE.

This translates approximately to:

to-lower-right() { tput cup $LINES $((COLUMNS-1)) }
zle -N to-lower-right
tput sc
to-lower-right
vared -f to-lower-right -p "%{$(tput cup 0 0)%}Enter something: " ...
tput rc

Other tricks may be needed to keep a newline from being output when
pressing ENTER to accept the edit.

If this is unsatisfactory, you could try using zcurses to manage the
display, which I think would allow you to always redraw whatever vared
erased.


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