Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)
- X-seq: zsh-workers 51137
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Millian Poquet <millian.poquet@xxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)
- Date: Thu, 8 Dec 2022 11:19:17 +0100
- Archived-at: <https://zsh.org/workers/51137>
- In-reply-to: <20221208100215.k2qcqdqgjlzwbdh7@chazelas.org>
- List-id: <zsh-workers.zsh.org>
- References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <CAN=4vMq2kc1cSV_0N-c6o32C3UR3hVSjE3mF+kV4pjcy7YR9=g@mail.gmail.com> <CAH+w=7aDn7SCv4Bao7ZQqtUaEv8EkvBXa15kM_nkF_GHLAcSFg@mail.gmail.com> <20221208082103.zg44mrv77jrizsaj@chazelas.org> <CAN=4vMrSO99rKMGhmO_yjtqYLUf+senu=Lhb=F47a9S6y8d7Hw@mail.gmail.com> <20221208100215.k2qcqdqgjlzwbdh7@chazelas.org>
On 12/8/22, Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> 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?
I have a patch for it, but I never sent it because I couldn't think of
a usecase. http://comm.it.cx/cgit/zsh-cvs/patch/?id=cf1ba693c9f3ed80ff085bfed74d854796349a0d
(I'm not 100% sure all the error checks are correct, and cover all
cases, especially wrt bart's private module).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author