On 11 August 2013 16:52, Dan Shelton <[email protected]> wrote:

> On 11 August 2013 07:55, Dan Shelton <[email protected]> wrote:
> > On 11 August 2013 07:50, Dan Shelton <[email protected]> wrote:
> >> Does anyone know a portable way (portable across most terminals that
> >> is, or maybe something which can be done with tput) to read the
> >> terminal cursor x position without using curses or ncurses?
> >>
> >> I'm asking because ksh93 has notorious problems with getting the
> >> cursor position correct if PS1-PS4 contain unusual escape sequences or
> >> characters which take more than one terminal cell (xterm256 color
> >> sequences or the unicode '...' character) which makes the set -o
> >> multiline mode unusable.
> >
> > Send too early. Yes, I've read
> > http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html, but it doesn't
> > help:
> > tput cup returns "i%p1%d;%p2%dH" and I have no clue how to grok that,
> > plus I only want to alter the X position and not Y too.
>
> tput cub1 and tput cuf1 move the cursor backwards and forwards. cub
> and cuf commands don't work for us because some terminals don't grok
> it (TERM=sun for example).
>
> Thomas, any ideas?
>
> Dan
> _______________________________________________
> ast-users mailing list
> [email protected]
> http://lists.research.att.com/mailman/listinfo/ast-users
>

I don't think it's possible to ask the terminal itself.  I think
curses/ncurses libraries keep track of the cursor position themselves, as
does the shell.

>> I'm asking because ksh93 has notorious problems with getting the
>> cursor position correct if PS1-PS4 contain unusual escape sequences or

There is an undocumented mechanism to quote escape sequences but I couldn't
get it to work, so it must still be experimental.  See edit.c if you want
to try it.

The other way that definitely works is to use a multiline prompt and put
all your escape sequences before the newline:

PS1=$'$USER@${HOSTNAME%%.*} $PWD\e]2;$USER@$HOSTNAME $PWD\a\n$ '

-- 
Regards

Danny
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to