3

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
wiredcontrol
  • 138
  • 8

1 Answers1

3

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:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Thank you! The first link led me to look for termcap and that led me to this answer (https://stackoverflow.com/a/11024208/1897481). From there, using `tput` I was able to get it working. – wiredcontrol Sep 13 '17 at 02:23