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

Re: wrap long lines



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday, August 29 at 01:38 PM, quoth Gary Johnson:
> 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.

Ahh, that's because the shell is, generally speaking, not running when 
that signal is sent. It's busy waiting for vim to exit. BUT that 
doesn't mean that you can't make it eval $(resize) after every 
command, for example.

In bash, say, you can play games with the $PROMPT_COMMAND, which is a 
command that gets executed every time a prompt is displayed. I 
generally use this for setting the title of my xterm, but you could 
also use it for running eval $(resize) again.

> This behavior is the same even when running bash.

Try this:

shopt -s checkwinsize

That should make bash be cognizant of terminals that have changed 
sizes unexpectedly.

> 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
>    $

What is happening is that your terminal is sending WINCH signals 
pretty much as fast as it can while you resize it. Your shell is 
dutifully trying to spawn that command every time, and you're ending 
up with several thousand resize commands all trying to execute at the 
same time.

Perhaps it might be better to do something like (this code won't work, 
I'm just writing it to give you the idea):

    trap 'untrap WINCH; eval $(resize); trap WINCH' WINCH

In other words: disable WINCH catching while you handle resizing, and 
then re-enable WINCH catching. This is, generally, a bad solution, if 
for no reason other than that you can miss an important WINCH at the 
end. But, it's better than the previous behavior.

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

HEH! :) I think HP/UX still wins. There's no reason to *not* send a 
SIGWINCH when the terminal resizes. It's much more sensible to send a 
bazillion than to not send them.

~Kyle
- -- 
It is dangerous to be right when the government is wrong.
                                                           -- Voltaire
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iD8DBQFE9LuxBkIOoMqOI14RAiWZAJ4ygZWpES9cRFTs3srzVuy2SAGZ3wCg/v6t
rKfWTdtp41XTKiF9C1m6mZQ=
=veDS
-----END PGP SIGNATURE-----