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?
This is discussed at length in the xterm FAQ Why doesn't the screen clear when running vi?.
ncurses as such doesn't do it. This is done by the terminal, given the escape sequences provided in the terminal description.
The behavior is from the alternate screen buffer, which was introduced with xterm in X10R4 (the end of 1986). xterm maintains two buffers:
xterm (and programs which use this feature, such as rxvt) recognizes escape sequences for switching between the two buffers. Since conventional termcap had no feature for this, the developers used the termcap initialization sequences ti
and te
(which correspond to terminfo smcup
and rmcup
). Technically the names refer to cursor-addressing mode, but no one cares (much).
The original xterm's alternate screen feature could be suppressed by removing at runtime the termcap ti
and te
capabilities (from the TERMCAP
environment variable), but that approach could not work with terminfo, which uses files. Since 1997, xterm has implemented a newer set of escape sequences which can be ignored by xterm. A few other programs allow the feature to be suppressed, but as a rule, those do not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With