How does the man program manage to restore previous terminal output after taking over the entire screen? Does it involve ANSI escape sequences in a way?
That is the ubiquitous xterm alternate-screen feature, which most terminal programs use via the terminfo smcup
and rmcup
sequences. For recent comments on this feature:
(By the way, the man
program is usually a "termcap" program).