On Sunday, March 30, 2003, at 08:06 PM, nobu.nokada / softhome.net wrote:

>> There are a surprising number of ruby source files that have newline
>> (\n) characters hardcoded as the line terminator--it appears that way
>> more than half of the files do.  Shouldn't these be set to a macro
>> that outputs $\ (or perhaps $,) character.  It seems to me that the
>> most of the places where ruby programs write directly to stdout are
>> not places where speed is of the essense (e.g., printing stack 
>> traces.)
>
> Interesting but I doubt its necessarity and worthfulness.

Likewise with your reply.

>> As a work around, I've dabbled a bit with doing traps in order to
>> issue an endwin before the exception gets printed, but I have not
>> found good documentation on how to do to traps, and it appears
>> impossible to raise or throw an exception within a trap proc block.
>
> begin
>   # codes with ncurses
> ensure
>   Ncurses.endwin
> end

I should have been clear that I want to have a trap or something in a 
file that can simply be required, so that I don't have to repeat the 
same begin/ensure/end stuff in every program.  I thought this was 
obvious because I mentioned that I have tried to use traps, but 
evidently it wasn't.

For example, requiring a file that contains the following trap ensures 
that you don't have to reset your terminal in the event of an untimely 
exit:

trap 0, proc {
	endwin
}

This, however, prints the staggered stack traces, which is what I'd 
like to fix.  Staggered stack traces are, to my mind, preferable to 
having to do wrap every piece of code in a begin/ensure/end wrapper.

My goal is to make the use of ncurses completely transparent--even more 
transparent than putting the begin/ensure/end blocker in a method that 
yields the WINDOW object.  It's not difficult, for example, to redo (in 
the same file that contains the trap code) the Kernel screen output 
methods (e.g., puts, print, etc.) accommodate ncurses, and doing so 
makes the fact that ncurses is being used transparent.

I am going to be gradually introducing ncurses based terminal 
capabilities to series of large and quite complex programs that are 
entirely readline/puts/printf based, and re-writing the UI layer all at 
once from the top isn't a viable alternative.  Thus, the change will be 
gradual, and the initial inclusion of ncurses must not require 
modification of the existing code.

-------------------------------------------------------
David King Landrith
   (w) 617.227.4469x213
   (h) 617.696.7133

One useless man is a disgrace, two
are called a law firm, and three or more
become a congress   -- John Adams
-------------------------------------------------------
public key available upon request