Search code examples
rubyscreenncursescurses

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.


Solution

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