Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)
- X-seq: zsh-workers 51131
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Millian Poquet <millian.poquet@xxxxxxx>, zsh-workers@xxxxxxx
- Subject: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)
- Date: Thu, 8 Dec 2022 08:21:03 +0000
- Archived-at: <https://zsh.org/workers/51131>
- In-reply-to: <CAH+w=7aDn7SCv4Bao7ZQqtUaEv8EkvBXa15kM_nkF_GHLAcSFg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Millian Poquet <millian.poquet@xxxxxxx>, zsh-workers@xxxxxxx
- References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <CAN=4vMq2kc1cSV_0N-c6o32C3UR3hVSjE3mF+kV4pjcy7YR9=g@mail.gmail.com> <CAH+w=7aDn7SCv4Bao7ZQqtUaEv8EkvBXa15kM_nkF_GHLAcSFg@mail.gmail.com>
2022-12-07 19:46:37 -0800, Bart Schaefer:
[...]
> get_cursor_pos() {
> print -n $'\e[6n'
Note that "print" already does \expansions without -r.
> IFS=$'\e[;' read -s -d R -A ${1:-reply}
The query sequence could be sent using the prompt string (on
stderr):
IFS=$'\e[;' read -sd R -A ${1-reply}$'?\e[6n'
Then assuming "read -s" does the right thing and disables
line discipline echo before printing the prompt, that would
remove the risk of the terminal's reply coming before the echo
is disabled.
curpos() {
IFS=$'\e[;' read -rsdR -t0.2 1$'?\e[6n' 1 ${2-y} ${1-x} 1 <> /dev/tty 2>&0
}
curpos col row
> shift 3 ${1:-reply}
Shouldn't that be shift 2?
terminal should reply \e[y;xR, which would be split into ('' '' y x).
Or do a strict parsing of the reply:
curpos() {
set -o localoptions -o extendedglob
local match answer
IFS= read -rsdR -t0.2 answer$'?\e[6n' &&
[[ $answer = (#b)$'\e['(<->)';'(<->) ]] &&
eval "${1-x}=\$match[2] ${2-y}=\$match[1]"
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author