HippoMan
HippoMan

Reputation: 2308

ruby: curses: Do not clear screen at end of program?

I'm using the ruby curses package (ruby 2.1.5).

In certain cases, I'd like the screen not to be cleared at the end of my program, so that the final contents of Curses.stdscr are still showing on my terminal when the program exits.

I've tried leaving out the call to Curses.close_screen, but the terminal screen still gets cleared upon exit.

Is there any way to tell curses in ruby to not clear the screen when the program is terminating?

Thank you in advance.

Upvotes: 2

Views: 785

Answers (2)

Thomas Dickey
Thomas Dickey

Reputation: 54475

The bundled Ruby curses module lacks (many) curses functions such as reset_shell_mode, which would be the usual way to do this:

The reset_prog_mode and reset_shell_mode routines restore the terminal to "program" (in curses) or "shell" (out of curses) state. These are done automatically by endwin(3x) and, after an endwin, by doupdate, so they normally are not called.

Alternatively, you could use MRuby (which provides the function).

In either case, exiting like this can leave your terminal's special keys set to application mode. The workaround for that would be to send an escape sequence (found in the terminal database as rmkx).

Upvotes: 2

HippoMan
HippoMan

Reputation: 2308

I figured it out: it turns out that if I exit my program with exit! instead of just exit, none of the screen resetting logic of curses gets invoked, and the latest contents of stdscr remain on my screen.

I also do the following before calling Curses.init_screen ...

require 'termios'
$orig_termios = Termios.tcgetattr($stdin)

... and I issue this command right before the exit! ...

Termios.tcsetattr($stdin, Termios::TCSANOW, $orig_termios)

(I want to accept this answer, but I can't do that for 2 more days. I will do so at that time).

Upvotes: 0

Related Questions