<<< Date Index >>>     <<< Thread Index >>>

Re: wrap long lines



On 2006-08-29, Kyle Wheeler <kyle-mutt@xxxxxxxxxxxxxx> wrote:
> On Tuesday, August 29 at 10:36 AM, quoth Gary Johnson:
> > On my Linux box with the default-for-here ksh:
> >
> >    $ trap 'echo SIGWINCH' SIGWINCH
> >    sh: trap: bad signal SIGWINCH
> 
> Mmmm, some versions of ksh require traps to be labelled somewhat 
> differently. This should work:
> 
>     trap 'echo SIGWINCH' WINCH
> 
> If all else fails, you can look up the signal number like so:
> 
>     grep SIGWINCH /usr/include/*/*.h
> 
> On my systems, it's signal 28, so this would work:
> 
>     trap 'echo SIGWINCH' 28

    $ echo $SHELL
    /usr/bin/sh
    $ file /usr/bin/sh
    /usr/bin/sh: symbolic link to /bin/ksh
    $ echo $KSH_VERSION
    @(#)PD KSH v5.2.14 99/07/13.2
    $ kill -l
    ...
    28  WINCH Window size change            60     60 Signal 60
    ...
    $ trap 'echo WINCH' WINCH
    $ WINCH
    WINCH
    WINCH
    
OK, this looks promising.  Now let's try this.  Open a new xterm.

    $ echo $LINES
    24

Make the terminal taller.

    $ echo $LINES
    24
    $ eval $(resize)
    $ echo $LINES
    30
    $ trap 'eval $(resize)' WINCH

Make the terminal taller again.

    $ echo $LINES
    35

Sweet!

It does have some limitations.  If I run vim in that terminal, then 
resize the window, vim correctly catches [SIG]WINCH and updates 
'lines' and 'columns', but when I exit vim, the shell still has the 
old values of LINES and COLUMNS.  This behavior is the same even 
when running bash.  On the other hand, I never do that when I'm 
actually using programs and not just testing stuff, so it's not a 
big deal.  And if I even do, it's still not a big deal to fix.

> > On my SunOS box:
> >
> >    $ trap 'echo SIGWINCH' SIGWINCH
> >
> > but I don't see anything when I resize the xterm window.
> 
> What shell? What version?

    $ echo $SHELL
    /usr/bin/sh
    $ file -h /usr/bin/sh
    /usr/bin/sh:    symbolic link to /bin/ksh
    $ echo KSH_VERSION

Nothing.  I love consistency.  [Read ksh man page.]

    $ set -o emacs
    $ ^V
    $ Version M-11/16/88i

"strings /bin/ksh" didn't reveal anything else.  The only other clue 
was in the man page:

    SEE ALSO
         ...

         Morris I. Bolsky and David G. Korn,  The  KornShell  Command
         and Programming Language, Prentice Hall, 1989.

> Check out the man page---there may be trap-related weirdnesses. When I 
> tried it on a SunOS box, it printed SIGWINCH after every line.

           sig can be EXIT, 0 (equivalent to EXIT)  or  a  signal
           specified  using a symbolic name, without the SIG pre-
           fix, for example, HUP, INT, QUIT, TERM. If sig is 0 or

Ah, again no "SIG".  Confirmed by "kill -l".

    $ trap 'echo WINCH' WINCH
    $
    WINCH

    WINCH
    $
    WINCH

    WINCH
    $

Odd interpolation of the shell prompt, but the trap did fire every 
time I resized the window.

    $ trap 'eval $(resize)' WINCH

Hmm.  I tried making the window one line taller.  The response was a 
bunch of newlines sent to the terminal, maybe 4 per second, for 
almost a minute, then this:

    sh: too many open files
    $

And the value of LINES is still the old value.  If I drag the window 
border slowly over a couple of inches,  I get

    $


    resize: unknown character, exiting.


    resize: Can't get rows and columns





    resize: Can't get rows and columns





    resize: unknown character, exiting.

    resize: unknown character, exiting.
    resize: Time out occurred
    resize: Time out occurred
    resize: Time out occurred
    resize: Time out occurred


> > On my HP-UX box:
> >
> >    $ trap 'echo SIGWINCH' SIGWINCH
> >    $
> >    SIGWINCH
> >
> >    SIGWINCH
> >    $
> >
> > but I get only one "SIGWINCH" for every roughly 12 window resizings.
> 
> Weird.

I think SunOS wins the weirdness competition.  It usually does.

I should mention that I'm doing all this from the Linux box, which 
is running the X server, and I'm rlogin'd to the HP-UX and SunOS 
boxes.

Regards,
Gary

-- 
Gary Johnson                               | Agilent Technologies
garyjohn@xxxxxxxxxxxxxxx                   | Wireless Division
http://www.spocom.com/users/gjohnson/mutt/ | Spokane, Washington, USA