[wellylug] Man-page formatting
Ewen McNeill
wellylug at ewen.mcneill.gen.nz
Thu Jun 30 22:24:11 NZST 2005
In message <1120124243.4408.14.camel at localhost>, Grant McLean writes:
>When you're running bash and you resize the window, bash gets a signal
>and updates $COLUMNS, but ... [...]
>If you're in another program in the text window such as man/less/vi, the
>foreground program gets the window change signal and bash doesn't, so
>when you get back to the shell, the value of $COLUMNS won't match the
>window size.
Interesting theory, but it doesn't seem to be the case here (Debian
Woody, XFree86 4.3 backport, xterm):
-= cut here -=-
ewen at basilica:~ $ echo $COLUMNS
80
ewen at basilica:~ $ less /etc/passwd
[.... resize window while less is running, then quit ....]
ewen at basilica:~ $ echo $COLUMNS
73
ewen at basilica:~ $ view /etc/passwd
[.... resize window while vim is running, then quit .....]
ewen at basilica:~ $ echo $COLUMNS
84
-= cut here -=-
SIGWINCH will be sent to the running application when the window
resizes, but this is basically just a hint "hey, something changed, you
might want to recheck the tty state". The actual window size is stored
in the tty, and can be retrieved with, eg, "stty -a", viz:
-=- cut here -=-
ewen at basilica:~ $ stty -a | head -1
speed 38400 baud; rows 58; columns 84; line = 0;
ewen at basilica:~ $
-=- cut here -=-
Most programs that cared, traditionally, would fetch the columns value
from the tty; indeed apart from "dpkg" (eg, "dpkg -l") I'm not aware of
much that respects the COLUMNS environment variable.[0]
And as far as I'm aware bash simply updates the COLUMNS environment
variable to reflect the tty value as a convenience; which can be
verified with a simple experiment:
-=- cut here -=-
ewen at basilica:~ $ echo $COLUMNS
80
ewen at basilica:~ $ stty columns 52
ewen at basilica:~ $ echo $COLUMNS
52
ewen at basilica:~ $ stty -a | head -1
speed 38400 baud; rows 58; columns 52; line = 0;
ewen at basilica:~ $
-=- cut here -=-
And resizing the window will reset both the tty columns value and also,
at the next bash prompt, the COLUMNS environment variable. The
alternative theory that bash is also receiving the SIGWINCH when a child
application does is disproved by running strace on $$ (the bash process
id) while running something else. Presumably bash also listens for
SIGWINCH to update it when you're sitting at the bash prompt ready for
the next command.
A similar experiment proves that less, at least, respects only the tty
columns value, and ignores the COLUMNS environment variable:
ewen at basilica:~ $ stty columns 35
ewen at basilica:~ $ COLUMNS=80 less /etc/passwd
will display wrapped at 35 columns.
Sitll I guess we should be grateful it's rare to have to reset the
rows/columns attributes by hand; I often found I needed to do that in
the past, sometimes with telnet sessions and more often with serial
sessions.[1]
Ewen
[0] "dpkg -l" behaves so poorly in the face of "narrow" (less than about
200 character) terminals, that "COLUMNS=200 dpkg -l" is something
of a habit. Fortunately they're apparently going to -- finally --
fix the most common situation in which that's an annoyance (piped to
another program) during the Debian Etch development.
[1] And I still do need to do it with serial consoles; "stty rows
58 columns 80; TERM=vt102" is pretty ingrained when something in
a serial console displays incorrectly.
More information about the wellylug
mailing list