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



Bart Schaefer wrote:
> > 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}

Aside from only working if the timing of the background process involves
writing to the terminal before the prompt is printed this approach also
has another disadvantage: the read can swallow any text that has been
typed before it prints the prompt. To see that, run something like sleep
3 and type your next command while it sleeps.

I've used a similar approach as a fallback mechanism[1] to detect a dark or
light background by printing '\e]11;?\a'. Typeahead is rarer for a new
window but I did add handling to try to grab the typeahead and restore
it with print -z but it still gets messed up occasionally; and I can't
be sure that all the typeahead was intended for zsh.

It might be better to report a bug for whatever programme you have that
forks and continues to write to the terminal from the child process
while the parent quits.

Oliver

[1] The primary mechanism is to look at $COLORFGBG which I typically add
to the list of variables that ssh/sshd will pass/accept.




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