From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3569 invoked by alias); 6 Sep 2015 11:54:50 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20521 Received: (qmail 21497 invoked from network); 6 Sep 2015 11:54:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 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== MIME-Version: 1.0 X-Received: by 10.140.100.182 with SMTP id s51mr3411203qge.25.1441540486669; Sun, 06 Sep 2015 04:54:46 -0700 (PDT) In-Reply-To: <2383721441536659@web21g.yandex.ru> References: <1441478205.9926.YahooMailBasic@web120002.mail.ne1.yahoo.com> <2383721441536659@web21g.yandex.ru> Date: Sun, 6 Sep 2015 13:54:46 +0200 Message-ID: Subject: Re: cursor position in a variable From: Mikael Magnusson To: ZyX Cc: david sowerby , Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, Sep 6, 2015 at 12:50 PM, ZyX wrote: > > > 05.09.2015, 22:07, "Mikael Magnusson" : >> On Sat, Sep 5, 2015 at 8:36 PM, david sowerby wrot= e: >>> I can get the cursor position by doing: >>> print "\e[6n" >>> this gives me the row and column. Though oddly the output appears afte= r the next prompt, not on its own line. This >>> may (or nor) be why when I do: >>> pos=3D$(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=E2=80=99s the point of using IFS with read -k? If you know that term= inal does print something the following works fine: > > print -n $'\e[6n' ; pos=3D ; while read -rs -k1 ; do pos+=3D$REPLY ; = [[ $REPLY =3D=3D R ]] && break ; done > > . Timeout I removed will be needed if you don=E2=80=99t know that termina= l 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 :). --=20 Mikael Magnusson