Zsh Mailing List Archive
Messages sorted by:
Re: cursor position in a variable
- X-seq: zsh-users 20521
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: ZyX <kp-pav@xxxxxxxxx>
- Subject: Re: cursor position in a variable
- Date: Sun, 6 Sep 2015 13:54:46 +0200
- Cc: david sowerby <d_sowerby@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=u7SHHlfnkmmW25vsQsh2zjYz+0I6d5zCAxawbx52ACE=; b=zSmgr+/aQFDefn8hlyh/SuJwmZhh7oOc2zyCm1DKd1Q/z7dFhxtUeRRJvPHAhYylup pztXczJV2RQWRwP4M7ddiGZdQBNIs+d95Da8qQBFnrqJCfXE2UTjWM3sxqDlF4mtAwfL zJcyNx8k/c/pmbzHrrmyaB1tfQnuMAsqWId+8xage090zqk+O8s7RZO8gy1eKlOiQQnI wr4hSakBKM+01CSWX8ML4vK++TCt1LP9LPgrWnQDwo91XP+Wny27ROTZ4Z3Tjyk0Gxz0 XAoMOJix3uhMWUhTGMcbKZ6Rz/DgDZZMeZx2DuCTe41tE5+J7p0gzHlGiCimfBcPnbw9 XxNw==
- In-reply-to: <firstname.lastname@example.org>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1441478205.9926.YahooMailBasic@web120002.mail.ne1.yahoo.com> <CAHYJk3QyZ8d+q9xrzpmRq+j5kVyL8nQYa2OQ2S7-aJtU4BzBLw@mail.gmail.com> <email@example.com>
On Sun, Sep 6, 2015 at 12:50 PM, ZyX <kp-pav@xxxxxxxxx> wrote:
> 05.09.2015, 22:07, "Mikael Magnusson" <mikachu@xxxxxxxxx>:
>> On Sat, Sep 5, 2015 at 8:36 PM, david sowerby <d_sowerby@xxxxxxxxx> wrote:
>>> I can get the cursor position by doing:
>>> print "\e[6n"
>>> this gives me the row and column. Though oddly the output appears after the next prompt, not on its own line. This
>>> may (or nor) be why when I do:
>>> pos=$(print "\e[6n")
>>> print $pos
>>> I get an empty line - and the output after the next prompt.
>>> I want to use the row the cursor is on in a script -- so how do I get that into a variable? If not this way is there a way using ZLE?
>>> thanks for any help --------------dave
>> When you print a terminal control sequence, the terminal writes the
>> reply on standard input, so you need something like
>> print -n '\e[6n'
>> read pos
>> The problem here is that the terminal doesn't print a newline, so this
>> will hang until you press enter. You can dance around with a loop
>> reading one character at a time and checking if there is more pending
>> input, but I'm not 100% sure what the best way to handle this is. If
>> 'read' had an option "read all pending input", it would be easy, but
>> it does not. :)
>>[snip kinda dumb code]
> What’s the point of using IFS with read -k? If you know that terminal does print something the following works fine:
> print -n $'\e[6n' ; pos= ; while read -rs -k1 ; do pos+=$REPLY ; [[ $REPLY == R ]] && break ; done
> . Timeout I removed will be needed if you don’t know that terminal will output anything though.
You're right, I coded in a bit of a circle there. I had the timeout in
case the terminal didn't print anything, but then added the loop to
wait until it did, so uh, not sure what I intended with that :).
Messages sorted by: