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 30231 invoked from network); 8 Dec 2022 10:02:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Dec 2022 10:02:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670493754; b=ZbtiplJHUPstcN4zIskYpedf5TtvL7cBUM3GZbycor9szq5D4a7oLtd4jhbd7Ur63WL6DZ9Mld 7jUPTrWZhbC9SwengQkWFx0kvd6yNUlgNWH0HFisMaBaPBKTggSV/1oxK6eeFpbIYs4LwxHxRC A1TmsGMeFJKd18wQatSr6b+KhMxm2oIydpdwNt0f8LRrodgfXYRlN3fy8uJ7fnupyQu6miVp48 FJDa09COaINRzVFXXZvbYiwD3Vbb6Yrxt2jgNiBHx4x/3j4Z27kgh+DQZTkG161mMq9xi0/Lff HEQYSWAfszEhYcvW/GSaFX9HwXQWlt4Xnm/FBlWqvQ/pOw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; 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=1670493754; bh=K+jF7PH95cXJjxpnCYh1RNR4tHgadmRcCsmDBMsmQT8=; 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=nyYnCzqqCi2XzpiXA13gSJ3eNHX5rjDd/wux6kZ0vKoQRE32vDlphFtzRY/AU115SMRcDMqoA9 Qnvq1jHOsuIDqFPkJcZ71zyAwhEYBpFxprSrs/3unT5U6xYLO5Wx8akROkwalcPGDkJw347jxg 9panXvQg6/XwS2fMToMXM6IaTYmZPOrBEJf3lZaFrqVLHouZoNix3dX6qPQVMRwN63PVdQW2oH bIjTaus3dEPJafo44osgiXpSOyrUVBUphd22gLnwFR5FKhxK5t7fgHwgnEGa7bFCDn+f8Jt66u OIeWsIL2vhQZHgK2qqbpn0fxqel/kH1QNydm6LS6Tc4UGA==; 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=ErMJZQj54yj7VB5kWpfEgflphmbJokxPo6B4Q61kaTw=; b=hTKagJEO14e2KYrLPWK/ew3J4x S1FmUm4N3k4ji9jMxBPfdRVZ/lfGhh/5IsKagGBeFA8hJvOKYP1MHX6G4B7WZFEi9CC9CaiBQgiti c1fWUccvf7jTGUVPFqX7mm8Km6wDE2vZwts2MHjWLdGDRYeEt0kpO2K/qLCGSCP7yvhQ8lZGoCGq+ u649qAE8OTjvtKiJ2wbOkQRPRXTurv3dCEWCqyNcjbpTkVES+ey0ZPSKmTGFC+tjHVrdWHoGcNYEn yZ/tzOe31qaHNXZapL7EWl1waV1LU+QUnf0zmIGO931+t2SYB7ptrJuKWdVfhKQCU7SpHMteOzdNl ngWxJnNg==; Received: by zero.zsh.org with local id 1p3Dje-0009oC-Ac; Thu, 08 Dec 2022 10:02:34 +0000 Authentication-Results: zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none Received: from relay6-d.mail.gandi.net ([217.70.183.198]:55327) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1p3DjO-0009Y0-CC; Thu, 08 Dec 2022 10:02:19 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id 0B5E0C001C; Thu, 8 Dec 2022 10:02:15 +0000 (UTC) Date: Thu, 8 Dec 2022 10:02:15 +0000 From: Stephane Chazelas To: Roman Perepelitsa Cc: Bart Schaefer , Millian Poquet , zsh-workers@zsh.org Subject: Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes) Message-ID: <20221208100215.k2qcqdqgjlzwbdh7@chazelas.org> Mail-Followup-To: Roman Perepelitsa , Bart Schaefer , Millian Poquet , zsh-workers@zsh.org References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <20221208082103.zg44mrv77jrizsaj@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 51135 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-08 09:34:41 +0100, Roman Perepelitsa: [...] > > 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]" > > } > > Functions that accept output parameter names as arguments are tricky. > The following won't work: > > # Which line is the cursor on? > curpos _ answer > print -r -- "The cursor is on the line number $answer" [...] Yes, I thought of using 3 as the intermediary variable, but decided against it as we can't do anything about match, mbegin... anyway. typeset -g "${1-x}=$match[2]" "${2-y}=$match[1]" Doesn't work either. I guess there's no way to access variables by the same name in that parent scope or to unlocal a variable? (bash does by exploiting some bug (calling unset -v in a severate function peels one layer of scoping instead of unsetting in the current scope)). -- Stephane