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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18899 invoked from network); 8 Dec 2022 08:21:42 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Dec 2022 08:21:42 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670487703; b=CvuNrMVGZEJ+fPLkc6StCvgcEinIKxmeVdhbl1unPmiVs8mgMFDuuPW+tJOMhy3rpvoRcWShb6 8zQUWYKaXcPW2zBXZxbrfKOO9SWYn01ZuNS0UOWTVDwtMvtlbzDU3JxczahUD3wfn/5mjvmb3n yRsAPE4eX3+QkXdvYuIGpWO+5ztz5iqboypgEEUpm2y3lFq4b6iq+wgez1EVKGP2GXFMkvB+Hs +qBPT+0cvHfqWqUCCfhfHyArHsu+Bxzc47NZJ32WS1ZdLflRsLP+GcGe6IP2G5uuY/R5FGFbqq 4JbY00ToDPEJqZ/pNAyA2Vr80RxbRPQbe0h6UKCOgZQUug==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1670487703; bh=caN2oFok+bBCR4Lr2/RkeWS1yrk2TYY36nGo1mWXwkY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=LdvOvyelR2g9dnXVXD3mhcljcI1+E+JYxDifZ+W3xpYradj6X8k9HZVsv4NdtaqprNr34l4oKR KmG1rk0OGFIgxSQupzL6wPZ6w/vRn62c+7YHEir7mU0vxKm1LviJsQy0qhJP3hk0nXIobmEAxq CKVVuosdRHpb+frYHT9pFoEBhi/NuFf7kx/c+orCPxtDkxF22iwxxp8u9ynK9JGv4jIHk5x5xy 4OTTxdtZkZfnQ9v4ic3jfq0Ti6e9ta0Dt6bqgry2MRyoAgbKjjJZpUPNr8rJb+NoG4LbfIshb0 n+XVbViez+G26aKBvoQIwV4uT2J20+Ql4J1lpezHolNieg==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Jo1atY7gR935iSqT2PmdBUEEz58iD1KPDxJk4dB3tg8=; b=dsVGaWIiOrFF1hl78YuxziAXmz l6wu5Iw8Qo5bIdkt6c4Wftb8H6//dZnl7t+9hRsm1hkR/J3x4b2nYcNqFwNe7VerdFiMzC5BU7LL+ hKC8htY2kkC2VMx6HYlX0sWRfb9iKQ53CmZz/CYQCvu2QHBMjOBDvowWBs/+uluddZqO2qkVj2DWA HPDsfxJju+T3wK0j3UVAB+cIoeodFyGqjvAR9lsFe09EqDMA4g+p1sCQ13ECxtC4jqA7Mu5YCyBhW hujjXw3MV3bfQlwJuvuSOuEAbCKItCnPLkv1w5CDqBg+lDSphIHi6Ql196O8m+omnlonPi5fLvVJA Uhw0LKiw==; Received: by zero.zsh.org with local id 1p3CA1-0005AS-AJ; Thu, 08 Dec 2022 08:21:41 +0000 Authentication-Results: zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; dmarc=none header.from=chazelas.org; arc=none Received: from relay1-d.mail.gandi.net ([217.70.183.193]:54379) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1p3C9S-0004rs-GG; Thu, 08 Dec 2022 08:21:06 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id 61096240002; Thu, 8 Dec 2022 08:21:03 +0000 (UTC) Date: Thu, 8 Dec 2022 08:21:03 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Roman Perepelitsa , Millian Poquet , zsh-workers@zsh.org Subject: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes) Message-ID: <20221208082103.zg44mrv77jrizsaj@chazelas.org> Mail-Followup-To: Bart Schaefer , Roman Perepelitsa , Millian Poquet , zsh-workers@zsh.org References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 51131 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: 2022-12-07 19:46:37 -0800, Bart Schaefer: [...] > get_cursor_pos() { > print -n $'\e[6n' Note that "print" already does \expansions without -r. > IFS=$'\e[;' read -s -d R -A ${1:-reply} The query sequence could be sent using the prompt string (on stderr): IFS=$'\e[;' read -sd R -A ${1-reply}$'?\e[6n' Then assuming "read -s" does the right thing and disables line discipline echo before printing the prompt, that would remove the risk of the terminal's reply coming before the echo is disabled. curpos() { IFS=$'\e[;' read -rsdR -t0.2 1$'?\e[6n' 1 ${2-y} ${1-x} 1 <> /dev/tty 2>&0 } curpos col row > shift 3 ${1:-reply} Shouldn't that be shift 2? terminal should reply \e[y;xR, which would be split into ('' '' y x). Or do a strict parsing of the reply: curpos() { set -o localoptions -o extendedglob local match answer IFS= read -rsdR -t0.2 answer$'?\e[6n' && [[ $answer = (#b)$'\e['(<->)';'(<->) ]] && eval "${1-x}=\$match[2] ${2-y}=\$match[1]" -- Stephane