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)



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