When you start the (n)curses program, it will remove the scroll bar from your terminal emulator, clear the screen, the scroll log (history) will also disappear. When you exit the program, the screen contents reappears, the scroll bar returns, and the scroll buffer returns.
How ncurses does it? I have studied all ANSI escape codes, I cannot see anything that can do such things. What is the technology behind this?
The technology is called The Alternate Screen Buffer. Terminal emulator provides two modes: primary and alternate. Alternate screen buffer has no scroll back, when you switch between these buffers the contents in them is preserved. To switch between them use smcup
and rmcup
ANSI Escape Sequences. In binary form they are:
$ tput smcup|hexdump -C
00000000 1b 5b 3f 31 30 34 39 68 |.[?1049h|
$ tput rmcup|hexdump -C
00000000 1b 5b 3f 31 30 34 39 6c |.[?1049l|