9

Today I was using glance tool in my office to monitor CPU utilization.When I run glance from terminal ,the command clears the screen and after all the work when I quit back to the terminal,the previous prompts are still there on my screen.I mean that I can see all the previous lines.My question is how is this effect of clearing screen achieved.If they had used command like clear,It should have cleared the whole screen,how did they manage to get back all the previous prompts ? I want to implement the same feature for some of my scripts.

Similarly when using vi command ,the screen is fully occupied and after exiting,we are able to view previous prompts as well.

g4ur4v
  • 1,764
  • 8
  • 29
  • 34
  • 1
    Apps like that use a terminal interface library such as ncurses. When it ends, you return to the shell where you were. – goldilocks Mar 12 '13 at 16:32

1 Answers1

8

Many terminal emulators maintain two copies of the terminal output: the normal screen buffer, and the alternate screen buffer. The normal buffer is for command line applications which normally don't move the cursor outside the current line and provides scrollback. The alternate buffer is for full-screen applications and does not provide scrollback.

Glance, vi and others switch to the alternate screen when they start and switch back when they exit.

In xterm, you can see the non-current screen by toggling “Show Alternate Screen” in the middle mouse button menu.

From a script, you can obtain the control sequence to switch between screens with tput smcup and tput rmcup (smcup and rmcup are the terminfo capabilities to switch into and out of full screen mode).

  • @Giles: Hi,Can you please have a look at this question ? http://unix.stackexchange.com/questions/67877/screen-buffer-and-dialog – g4ur4v Mar 14 '13 at 07:41