How to prevent GNU Screen from switching screens upon termination and detach

This blog post explains how to prevent GNU Screen from restoring the original terminal window contents upon a termination or a detach. The original terminal window contents is how the terminal window looked like before attaching. This is useful if a short-running command is running in Screen and you are interested in its final output.

Run this once:

(echo; echo 'termcapinfo * ti:te') >>~/.screenrc

Screens attached after running this won't restore the original terminal window contents.

Explanation: ti is the termcap equivalent of the terminfo entry smcup, and te is the termcap equivalent of the terminfo entry rmcup. They describe how to switch to the alternate screen and back. Setting them to empty will prevent Screen from switching to the alternate screen upon attach, and switching back to the normal screen upon termination and detach. Read more about these directives on http://chenyufei.info/blog/2011-12-15/prevent-vim-less-clear-screen-on-exit/.

Unfortunately, Screen still moves the cursor to the last line, and writes the [screen is terminating] message by scrolling down to the next line. This can't be disabled, it's hardwired to the GotoPos(0, D_height - 1); call in FinitTerm() function in display.c . Printing many newlines when starting the Screen session improves the situation a bit, because it moves the cursor down.

No comments: