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

Re: prompt and prompt_cr option

On Mon, 11 Oct 2004, Danek Duvall wrote:

> On Mon, Oct 11, 2004 at 03:11:43PM -0700, Bart Schaefer wrote:
> > For certain types of terminals you might be able to query the current 
> > cursor position and do something clever when it is not in column zero
> On the other hand, you could write a precmd function that did this and 
> spit out an extra newline if necessary (and set nopromptcr), no?

Unfortunately it's not quite that simple.

As far as I can tell, there's no terminfo/termcap capability that defines
the "report cursor position" string.  So it can't easily be determined
whether the terminal supports it, or what to send.

If the terminal is ANSI/ECMA compliant, the query string is $'\e[6n' and 
the response is $'\e[ll;ccR' where cc and ll are the column and line 
numbers -- but if it is not ANSI then sending that string won't give any 
response (and may just garble the output further).

So the following might work, or might not.  It uses the prompt printed by
the read builtin to query the terminal and the combination of IFS and the
-d option to parse the response.

  precmd() {
    local escape colno lineno
    IFS='[;' read -s -d R escape\?$'\e[6n' lineno colno
    (( colno > 1 )) && echo ''

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