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
- X-seq: zsh-workers 51139
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Millian Poquet <millian.poquet@xxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: [bug report] prompt can erase messages written on the terminal by background processes
- Date: Thu, 08 Dec 2022 16:03:07 +0100
- Archived-at: <https://zsh.org/workers/51139>
- In-reply-to: <CAH+w=7aDn7SCv4Bao7ZQqtUaEv8EkvBXa15kM_nkF_GHLAcSFg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <CAN=4vMq2kc1cSV_0N-c6o32C3UR3hVSjE3mF+kV4pjcy7YR9=g@mail.gmail.com> <CAH+w=7aDn7SCv4Bao7ZQqtUaEv8EkvBXa15kM_nkF_GHLAcSFg@mail.gmail.com>
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