Most terminal emulators can save and restore screen contents.
The terminfo codes for this are: smcup to enter full screen mode and rmcup to leave it. (Higher termcap ti and te codes.)
If these features are included in the terminfo database, any program using ncurses will print the smcup line when writing and the rmcup line when exiting.
On the system I'm currently using, the lines (with \E representing the escape character):
smcup: \E7\E[?1;47h rmcup: \E[2J\E[?1;47l\E8
This restores the previous screen contents as well as the cursor position.
The specific sequence values ββ(for xterm) are described here :
- smcup:
\E7 Save cursor\E[?1;47h Application cursor keys; Using an alternate screen buffer
- rmcup:
\E[2J Erase screen\E[?1;47l Application cursor keys; Use regular screen buffer\E8 Restore cursor
(This assumes that I am using the semicolon correctly, I am not 100% sure.)
Keith thompson
source share