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

Re: [bug report] prompt can erase messages written on the terminal by background processes



On Thu, Dec 8, 2022 at 4:46 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Wed, Dec 7, 2022 at 2:57 PM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > On Wed, Dec 7, 2022 at 8:04 PM Millian Poquet <millian.poquet@xxxxxxx> wrote:
> > >
> > > prompt can erase messages written on the terminal by background processes
> >
> > There is no way around it. Zle assumes that nobody else prints to the terminal.
>
> Perhaps try this.
>
> get_cursor_pos() {
>   print -n $'\e[6n'
>   IFS=$'\e[;' read -s -d R -A ${1:-reply}
>   shift 3 ${1:-reply}
> }
> precmd() {
>   local rowcol
>   get_cursor_pos rowcol
>   if (( $rowcol[1] > 1 ))
>   then print
>   fi
> }

Here's the simplified version of Millian's test:

    % setopt prompt_subst; PS1='%# $(sleep 2)'; ( sleep 1; print -n hello ) &!

This prints "hello" and then erases it. The precmd hook runs before
prompt expansion, so it has no effect.

Even if this somehow worked for this test case, it would merely mask
the problem. Zle has to assume that nobody else writes to the TTY.
It's user error to violate this assumption.

Roman.




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