Some of the linux commands like less
or man
display their output in the current terminal occupying the whole screen. But the previous interactions reappear as is once the program quits.
How can we achieve the same behavior for our custom program?
Thank you.
Actually,
less
and comparable programs use a termcap interface which could be provided by various libraries. The point of the question asked how the "previous interactions" could be restored. That is a feature of xterm and other programs called the alternate screen, which conventionally is used via the terminal capabilities for starting and ending cursor-addressing mode. The feature is completely terminal-dependent (ncurses only provides the information).Further reading: