Unix Programming - Re: Get current screen location (was: Re: Terminal output with escape sequences: Any [

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2007 > Re: Get current screen location (was: Re: Terminal output with escape sequences: Any [





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Get current screen location (was: Re: Terminal output with escape sequences: Any [
Stephane CHAZELAS

2007-10-24, 7:31 am

2007-10-24, 03:37(-04), Chris F.A. Johnson:
> On 2007-10-24, Markus Mayer wrote:
>
> I use this shell function:
>
> _curpos()
> {
> stty -echo;
> printf '\e[6n';
> read -d R _CURPOS;
> stty echo;
> _CURPOS=${_CURPOS#??};
> _CURX=${_CURPOS#*;};
> _CURY=${_CURPOS%;*}
> }

[...]

Note that read -d is zsh/bash/ksh93 specific (and you need
recent versions). With ksh93 (at least the ksh93s+ I have access
to), it doesn't work, it does seem to disable the cooked mode like
the other shells, but you still need to enter a newline
character (via <Ctrl-J>!), for read to return.

Portably, you can use dd, either by reading one character at a
time until you find "R" or using the terminal timeout as in my
suggestion.

Also, the local echo might already be disabled before the call
to _curpos, so you may want to not do a stty echo afterwards but
instead to save the settings and restore them afterwards.

In zsh:

STTY=-echo read -dR $'_CURPOS?\e[6n'


--
Stéphane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com