How to get an overlay output for a command in terminal like less or man?

602 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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: