From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16303 invoked by alias); 26 May 2017 14:46:05 -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: 22716 Received: (qmail 14842 invoked from network); 26 May 2017 14:46:05 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f46.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.46):SA:0(0.5/5.0):. Processed in 1.716076 secs); 26 May 2017 14:46:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM, SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: jahvascriptmaniac@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.214.46 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=yTM2//6yXd5Apj+561W4DPWlmwSmFnrWU81lvlhq/p0=; b=eSlAE9yd+lyCOp/+Sb4xTLwWmKmmjb+rc9OuQZ2deKsNNOO62z6o9HE/Cw29H6jfoR HvhrMJRKzszennRrP8nCVg93J0KmKa5pqRVm2RYvbgx/Mb2nZvKKb2AtQ817EPfhWyGa gn70vmjtE7AXP1mV1pRgC7Xt77YWKgXWSxhbR38rpmpK43BFU/jaI9HwjZxxoDTNZLSe HXj1pDW0ZRD5FoOXalP2Bf06jrwhCoWE+s2DAOFiqFMsqUPDT0rsziZ2dkVqnI5XszAI iFtUsHA/izgUxKhw89H8hsugeEhx1Zfp6BjbV9LcTd5WF3NacWXVKwd9oh9gIx8Z6XwI oihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=yTM2//6yXd5Apj+561W4DPWlmwSmFnrWU81lvlhq/p0=; b=ZjIymE5bIfkBq1wVFGojdErF9NfQp3lTXNlBRQuEh45Fy6JhHM+QYnJHF8sVr4apCK zF5ZgT/sCBB7db4BHc1Aw66JYsRNt2UePthU3HAzh3gmUga/78iNZdZVjxu6kXLrg6pg ONXMxg1WQFGjiVvC9ZtCO8nxCXZV16FXxjc1KMb69srbvoERjuH1blq1WtBq41yHgWNw yUOVqutNNtaVOErcqxHh2WmdcaxpZr1vYNwbew8mlSarW70zIDFQUyZPheKPiYHCBmPn PWDDUIXzlNgMqkeW9naF3BJY28z4w2p20A0r1jB1PawTol71RNARrX5PsoYSTqI9PZrA Y4aA== X-Gm-Message-State: AODbwcCvQuu6NlBIRc2jOW+huFfYIGhtuc4v4jPinHOnozA9XdA9Q2j1 ZNwWHVoKx5s0niKcgz7JCvp7KYfBYQ== X-Received: by 10.36.242.133 with SMTP id j127mr3046539ith.67.1495809959958; Fri, 26 May 2017 07:45:59 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Dup=C3=A9ron_Georges?= Date: Fri, 26 May 2017 16:45:39 +0200 Message-ID: Subject: How to call zle -U while drawing the prompt? To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello! I am trying to get the current cursor position (in lines and columns w.r.t. the top left corner of the console) while drawing the ZSH prompt. My actual goal is to display more or less verbose information below the "actual" prompt line depending on how much space is available. In order to know the current cursor position, I need to send the escape sequence \e[6n to the terminal, and it replies with \e[Y;XR . If the user typed some input before the cursor position is read (e.g. during the "sleep 1" in the example below, or while .zshrc is initially running when opening a new terminal), then these characters are discarded. I tried to re-add these characters to ZSH's input buffer by calling zle -U "$userinput", but I get the error "can only be called from widget function". How can I: * Call zle -U while drawing the prompt? * Or otherwise force zsh to either read all input just before I send \e[6n to the terminal? Thanks! Georges Dup=C3=A9ron # This is the short .zshrc I use: setopt prompt_subst MY_PS1(){ local stuff line userinput # simulate some work: sleep 1 # request the cursor position echo -ne "\033[6n" > /dev/tty read -s -d 'R' stuff < /dev/tty line=3D"${stuff##*\[}" line=3D"${line%;*}" userinput=3D"${stuff%\[*}" # re-inject the already-typed text zle -U "$userinput" echo "prompt:" } PS1=3D'`MY_PS1`'