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

Re: wrap long lines



On 2006-08-29, Kyle Wheeler <kyle-mutt@xxxxxxxxxxxxxx> wrote:
> 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.

Yep, that worked.

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

OK.  I wrote a helper script, trap_aid:

    $ cat ~/lib/trap_aid
    trap "" WINCH; eval $(resize); trap ". ~/lib/trap_aid" WINCH

and then executed:

    $ trap ". ~/lib/trap_aid" WINCH

It seems to work pretty well!  I think I'll change the script to a 
function, put it all into my ~/.kshrc, and see how it works in 
practice for a while.

Thanks very much for all the explanations and suggestions.

Regards,
Gary

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