From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3103 invoked from network); 8 Dec 2022 15:03:30 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Dec 2022 15:03:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:References:From:In-reply-to:To:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=KIEEqRtcyTpEkdkpPrRp1fJN497P7ZONLG/k5KbsOZc=; b=gmaXQHT536SS4LyrMXFIkPTXdE XB/dDefWFWnxo6fzp4wMH+zdNRWdZXnVoQC7R93+zXQEI953oNDj4iH+j/9IbGBW8NhBd+5bBxB4+ j9ABIB2LK+pI+g5o6+fHHkvxZLolo2VgAaoFNUyNsKZou52NI4ntEE18aqyutTAzMMNCx400WRFrE 7E1QAoJLwz/L811MPxEU1mz9FouGJTOgri6x9fZljZqlDv92AhekzEqeqg2ZYIRORLO5ffoI+EK5u +Tk1p1N/qR0PQdiI1QTdqtYyKIs36fihFuF8OqEK1mNjl0PGzN9R8i9DXukzx6QXyLaa7D7RVb1tb 5WCwN/Jg==; Received: by zero.zsh.org with local id 1p3IQr-000IvA-MF; Thu, 08 Dec 2022 15:03:29 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p3IQX-000Ibe-Ut; Thu, 08 Dec 2022 15:03:10 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1p3IQV-000AGb-BP; Thu, 08 Dec 2022 16:03:07 +0100 To: Millian Poquet , zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> Subject: Re: [bug report] prompt can erase messages written on the terminal by background processes MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <39467.1670511787.1@hydra> Date: Thu, 08 Dec 2022 16:03:07 +0100 Message-ID: <39468-1670511787.350409@tM9p.ctXg.8m2T> X-Seq: 51139 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 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.