zsh-workers
 help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: zsh-workers@zsh.org
Cc: Bart Schaefer <schaefer@brasslantern.com>,
	Stephane Chazelas <stephane@chazelas.org>
Subject: Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)
Date: Fri, 9 Dec 2022 13:46:21 +0100	[thread overview]
Message-ID: <CAGdYchvNLkmDcPWRXrrmH6r7qZUt8PojXpVcZSagiRMDUVx9Wg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aUz2FFiUPn3tma__hW=pK05whjrU+_g9rBAnsDz_LMHA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

>
> 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
<https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fparam_002fprivate-Module>,
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

[-- Attachment #2: Type: text/html, Size: 2063 bytes --]

  reply	other threads:[~2022-12-09 12:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 19:02 [bug report] prompt can erase messages written on the terminal by background processes Millian Poquet
2022-12-07 22:55 ` Roman Perepelitsa
2022-12-08  3:46   ` Bart Schaefer
2022-12-08  8:21     ` Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes) Stephane Chazelas
2022-12-08  8:34       ` Roman Perepelitsa
2022-12-08 10:02         ` Stephane Chazelas
2022-12-08 10:10           ` Stephane Chazelas
2022-12-08 10:19           ` Mikael Magnusson
2022-12-09  2:19           ` Bart Schaefer
2022-12-09 12:46             ` Philippe Altherr [this message]
2022-12-10  4:30               ` Bart Schaefer
2022-12-10 14:55                 ` Private variables not private enough? (Was: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)) Philippe Altherr
2022-12-10 17:36                   ` Bart Schaefer
2022-12-10 20:38                     ` Bart Schaefer
2022-12-11 18:00               ` Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes) Stephane Chazelas
2022-12-09  1:39       ` Bart Schaefer
2022-12-08  8:45     ` [bug report] prompt can erase messages written on the terminal by background processes Roman Perepelitsa
2022-12-08 15:03     ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGdYchvNLkmDcPWRXrrmH6r7qZUt8PojXpVcZSagiRMDUVx9Wg@mail.gmail.com \
    --to=philippe.altherr@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=stephane@chazelas.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).