From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26564 invoked by alias); 5 Sep 2015 19:05:55 -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: 20517 Received: (qmail 19485 invoked from network); 5 Sep 2015 19:05:54 -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; bh=IIOaYCYEgM5zHWeOow9bXj8ZYohKvDCx8jcsfVei6iY=; b=ScA1ghWr1RhBb7TZmu8rolqC2iSEfm/TB4/j3i1xZPgIM/neWvHkD8JXTQSyN9htjg bOaEm5Ezd1NYKY5P2gMl/clL/MoGTPWQz/5esJASWUVcHqFxi16thF5ZG4101n0FaNBw JVd6gRfpO2R2Ml/LjqIkymSu9UZ2xdtSJuHJPreLvIyRjeAPmZ/q4TR1GXpyaWbSlfMB FYshsfNOs86ieIZ/Y9J2AUHud83TbvAE9lZiLuRoO0rfbcNbG0szXDLNgYccuGn4Q9AB HHNO2HtoklmlHwGc60ZsXHWj9w8APsbBsQ0aX6n1jWTA7JbgnAWu6chvyklwKk03zHkH jIHw== MIME-Version: 1.0 X-Received: by 10.140.233.7 with SMTP id e7mr16229472qhc.79.1441479950927; Sat, 05 Sep 2015 12:05:50 -0700 (PDT) In-Reply-To: <1441478205.9926.YahooMailBasic@web120002.mail.ne1.yahoo.com> References: <1441478205.9926.YahooMailBasic@web120002.mail.ne1.yahoo.com> Date: Sat, 5 Sep 2015 21:05:50 +0200 Message-ID: Subject: Re: cursor position in a variable From: Mikael Magnusson To: david sowerby Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Sat, Sep 5, 2015 at 8:36 PM, david sowerby 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. :) print -n '\e[6n' pos= while IFS= read -rs -t 0.1 -k1; do pos+=$REPLY; done echo ${(V)pos} this "works", but the 0.1 feels hacky. With 0, the whole loop might abort before the terminal has time to write any characters back. print -n '\e[6n' until IFS= read -rs -k1 pos; do done while IFS= read -rs -t 0 -k1; do pos+=$REPLY; done echo ${(V)pos} this variant will spin until it gets one character back, then read the rest of the pending characters. You may also want to abort that loop when you get the "R" back. ...; do pos+=$REPLY; [[ $REPLY == R ]] && break; done -- Mikael Magnusson