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,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 11820 invoked from network); 9 Dec 2022 12:47:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Dec 2022 12:47:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670590029; b=YAMoQqbs2jvb6xxDl/FK7zQRO0XnF61akNyxpUx8Nzcgy06yJab919/xg96FFhA+wQXlVQwhIr AX2JEPpk4+WhWKFXjlK84ipAg4bvgMPzUvNvM6GPk6EaFe4c8HHFP0vbpw58Ua663SaP6ScPqM /9vdeFWro9/zkCaA0zZ4soN+tF6kX6XwyyDTVzax4vMsGKKKlEJxBUrLorQmMX7nJAmfBNKJMN xcnnmVHT9BWNzOJQ6c8ajyILiO9mX7+U6M89QL09YjLbrsIsrRiMBXeqooyCVt/RLvp/25Qr+3 fdFw1EenRZa0NNDwfqTHHDp8PItZGsf+jnju1d38LZ7sEA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vk1-f175.google.com) smtp.remote-ip=209.85.221.175; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1670590029; bh=PC/SlKCcZ2JG03xR1BvObo89u8YC8E9ae5ChgtvCRR4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=Uz//JFDteA2Jo0+xJTEO4YR86iBiZc1iQzC5OZqb0K2SCkflpeaVxTPW3gp0qjAhx598xCzCtI J1iLeYi0GRB6Bq7lkc2es1nMX3OamSqZjncjNI9XWMM+KNdA1XO0tntVqcXO/IRVDfbboaxoLN PPc2TfJaTqkslZHbxKJ0U4tHdf5x3ZLRrPRh5CqvrGzsGbrk2fsm3AaJ7lnPbL8MdDI7CnvYwD /RJBt8tQtKf83G4ae4+I9Tju86mtZVAFLvZ+RTwLEYQQnC1+Co5wx6dM8N9Wz46DJWdfMk6IfK xuB3amstPlimivFso6/B1tRFmOYc9Djk02EFWZgDXGWONA==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=tuM/DA2zC61HUa+w5pPihcZ1HuKaocCRstkJpoupAHs=; b=X07BZdxRBWECbSKUZlnEelZWdd CpYgRqxScVfrGW2aAg4zAkwp5PDWmuySVMG5pBZu3NV7ijXFhzuKoqcmbwUVA1tdWmeVhPATTZwPJ eUouMQy7GaJBIABq9jvQWvyeuGi0aMm86/4tzkw1wE5ejxNu59NhspGHZGx1VH4Z4wtzPgIypBeBQ 7yY6TENO+nn12VQpoTDnNmhHxUa9pQBIOTGD/1qqBShIqPWdkRItEjrT3EgnYUXlKH4FMDq1sNPDv M8ywGsvbkpcowolp6/Cqx0GzY3oH2nAA/iDNFkZ95ZXvWq02taOPgsJtpehim2TvvHD39qIPa2pqh lRMIyUMw==; Received: by zero.zsh.org with local id 1p3cmR-0006HD-GT; Fri, 09 Dec 2022 12:47:07 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vk1-f175.google.com) smtp.remote-ip=209.85.221.175; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vk1-f175.google.com ([209.85.221.175]:38535) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1p3clv-0005y3-3h; Fri, 09 Dec 2022 12:46:36 +0000 Received: by mail-vk1-f175.google.com with SMTP id v81so2065743vkv.5 for ; Fri, 09 Dec 2022 04:46:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tuM/DA2zC61HUa+w5pPihcZ1HuKaocCRstkJpoupAHs=; b=mRjfkV1JNYEKE1Gw4vU6K+tfHTqOv84x+bNCMSE4EptBqWFN3mdXEAjDNFsIGm1zKT rdY0ufwdrj7QhjVtOJiP0dN/O2Se0ls17JhsdOLN7/PmoFfnorCsLJThnsjRzPexIQwm mHQqoEyPWiqtB25bIMBQJ3vE4OXgVvOWNpD9yLrFrbn2TSw03PFPPl4ya0OCCHTR1xb8 f41GG6CkjPMDRU0GOXNQBqZgMUh9hYXOi2JrL6X8P6IKCtJQNQxSnHMq5uTmxgmOVJT8 wOnj7gdRZuADZKBnzBzrp2N4pNlYzlU8Wqes6EoAJ+BzxxmzzN0ddEPqqyON/WMznFRH DQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tuM/DA2zC61HUa+w5pPihcZ1HuKaocCRstkJpoupAHs=; b=JMxJ2VTIoIqAi2VZNeR82ku/04p0ei0eyt3RvoHjo+PNlre+vw2A+lpyL4Dcp7gNRN TXRwoKIT3o+FF8Qx+b59rh580bFovFWybDQWT6vb6l6c+M+0XBdxYh1EBV1jZHsNaDqM Ixn9VsyXxQTEICzM2UgH0d2Ej544nynwbv3vPYjR+2EhAYx+BLIdmfcWUee5q3Vn/NdV ogMXFknOI7/Tm4oEboQ/MLQ7hQ3TMGXk3CdJUYW6OjTTNEmGISVH54Hx23oXU9+iyRQl wHTf8GKPY8wJlSidxJ4wNZyoUMn+5HQtN9JmsqXad2c+ZDbisXUpHjzNotp1phK24JoJ /hlg== X-Gm-Message-State: ANoB5pkmX+AvXKI768s9gDWNYv50u8+DP3iHYTwIYYnDzt9WHX9jna0W cVktFNv1OsESaEe/ybsdaLl759/q+KFh2hDFqYE9IZXKeTI= X-Google-Smtp-Source: AA0mqf6YWgg6yim6jk5hGL3cn84g/KkGybz42yti7Qu4C/L61psO3mAQQwj8U2MI9h2NUSSKwiftoO8w4iHvxxvrrK8= X-Received: by 2002:a1f:5042:0:b0:3bc:e09a:3903 with SMTP id e63-20020a1f5042000000b003bce09a3903mr26388658vkb.23.1670589992536; Fri, 09 Dec 2022 04:46:32 -0800 (PST) MIME-Version: 1.0 References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <20221208082103.zg44mrv77jrizsaj@chazelas.org> <20221208100215.k2qcqdqgjlzwbdh7@chazelas.org> In-Reply-To: From: Philippe Altherr Date: Fri, 9 Dec 2022 13:46:21 +0100 Message-ID: Subject: Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes) To: zsh-workers@zsh.org Cc: Bart Schaefer , Stephane Chazelas Content-Type: multipart/alternative; boundary="00000000000012122205ef648b58" X-Seq: 51152 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: --00000000000012122205ef648b58 Content-Type: text/plain; charset="UTF-8" > > 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? I just stumbled on the module zsh/param/private , which makes it possible (but I won't claim that it's very practical): assign() { > print -v "$1" "$2" > } > > curpos() { > set -o localoptions -o extendedglob > # Initialize the return variables. Without this, print -v fails if > # the variable is the same as one of the private variables. > eval "${1-x}= ${2-y}=" > zmodload zsh/param/private > local -P -a match mbegin mend > local -P answer > IFS= read -rsdR -t0.2 answer$'?\e[6n' && > [[ $answer = (#b)$'\e['(<->)';'(<->) ]] && > assign ${1-x} "$match[2]" && > assign ${2-y} "$match[1]" > } > > curpos answer match > echo x=$answer y=$match > It's a bit strange that the initialization is needed. Private variables don't hide global variables of the same name, nor prevent their assignment, but prevent their initial declaration. Philippe --00000000000012122205ef648b58 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
typeset = -g "${1-x}=3D$match[2]" "${2-y}=3D$match[1]"

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">Doesn't work either. I= guess there's no way to access variables
by the same name in that p= arent scope or to unlocal a variable?

I ju= st stumbled on the module=C2=A0zsh/param/priv= ate, which makes it possible (but I won't claim that it's very = practical):

assign() {
=C2=A0 =C2=A0 print -v "$1" "$2"
}
curpos() {
=C2=A0 =C2=A0 set -o localoptions -o extendedglob
=C2= =A0 =C2=A0 # Initialize the return variables. Without this, print -v fails = if
=C2=A0 =C2=A0 # the variable is the same as one of the private variab= les.
=C2=A0 =C2=A0 eval "${1-x}=3D ${2-y}=3D"
=C2=A0 =C2=A0= zmodload zsh/param/private
=C2=A0 =C2=A0 local -P -a match mbegin mend<= br>=C2=A0 =C2=A0 local -P answer
=C2=A0 =C2=A0 IFS=3D read -rsdR -t0.2 a= nswer$'?\e[6n' &&
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [[ $answer= =3D (#b)$'\e['(<->)';'(<->) ]] &&
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 assign ${1-x} "$match[2]" &&<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 assign ${2-y} "$match[1]"
}
=
curpos answer match
echo x=3D$answer y=3D$match

It's a bit strange that the initialization is needed. P= rivate variables don't hide global variables of the same name, nor prev= ent their=C2=A0assignment, but prevent their initial declaration.

Philippe

--00000000000012122205ef648b58--