From: "Dupéron Georges" <jahvascriptmaniac@gmail.com>
To: zsh-users@zsh.org
Subject: How to call zle -U while drawing the prompt?
Date: Fri, 26 May 2017 16:45:39 +0200 [thread overview]
Message-ID: <CAKQnwqadKiW_UTJPzERKzE=EEpEggSjq3cG8EHNKyznC5V1WHA@mail.gmail.com> (raw)
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`'
next reply other threads:[~2017-05-26 14:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 14:45 Dupéron Georges [this message]
2017-05-27 0:10 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKQnwqadKiW_UTJPzERKzE=EEpEggSjq3cG8EHNKyznC5V1WHA@mail.gmail.com' \
--to=jahvascriptmaniac@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).