How do I get vi to know my window size?

Rob Landley rob at landley.net
Tue Sep 19 21:11:38 UTC 2006


On Tuesday 19 September 2006 6:05 am, Paul Fox wrote:
> i have a feeling i may already have posted the code i'm using, or
> a reference to it, to the list a while back.  check the archives, or
> ask me for a copy -- it's only a few pages long.  for copyright
> conflict reasons it can't become an applet, though it would be nifty if
> someone would rewrite it so that it could be included in busybox.

Who exactly are you testing the current size _from_?  (Is your xterm 
responding to the ansi escape sequence when it tries to display it?)  If so, 
I could just add this behavior as a config option to 
get_terminal_width_height() in libbb (a fallback for when we get 0/0 as the 
size).  The hard part's figuring out when it's safe to do it.  (Hmmm, poll 
with an immediate timeout on stdin and only do it if no input is waiting, to 
avoid getting confused by "echo blah | program"...  And then you'd need a 
similar poll with quick timeout on the read, but how quick is quick?  It 
should definitely fall back to reading the environment variables $LINES and 
$COLUMNS _first_ before trying an ANSI probe.  And it would miss resizes 
after the program started...)

Hmmm...

(Talking about ANSI escape sequences always brings back memories.  (One of my 
first original C programs was an ansi screen driver (doing the whole direct 
screen writes under dos thing many times faster than the bios did) back in 
1990.  Before that, I mostly modified existing C programs, or wrote original 
ones in Commodore 64 BASIC. :)  I remember I had a file over 100k long (don't 
laugh, it was a lot back then) a session capture of viewing lots of 
consecutive messages from the WWIVnet Ansi Art Gallery.  I used it to test my 
code for correctness, and later as a performance benchmark.  I'm glad 
that "echo -e '\e[8m'" doesn't work in Linux.  Or "\e[...p" to attach macros 
to keyboard keys.  Now _there_ was a fun security issue...)

Let's see, the sequence to do this would be something like...  (Googles for 
_extremely_ old references...)  echo -e "\e[s\e[999C\e[999B\e[6n\e[u"
And then poll with a half-second timeout for the response string (looping on 
short reads until we get the R or a timeout).  Hmmm... What code queries for 
a TTY again?

Putters off to look at code...

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list