Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)



On Thu, Dec 8, 2022 at 9:21 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> 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]"
> }

Functions that accept output parameter names as arguments are tricky.
The following won't work:

    # Which line is the cursor on?
    curpos _ answer
    print -r -- "The cursor is on the line number $answer"

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author