Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
How to call zle -U while drawing the prompt?
- X-seq: zsh-users 22716
- From: Dupéron Georges <jahvascriptmaniac@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: How to call zle -U while drawing the prompt?
- Date: Fri, 26 May 2017 16:45:39 +0200
- 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==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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éron
# 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="${stuff##*\[}"
line="${line%;*}"
userinput="${stuff%\[*}"
# re-inject the already-typed text
zle -U "$userinput"
echo "prompt:"
}
PS1='`MY_PS1`'
Messages sorted by:
Reverse Date,
Date,
Thread,
Author