OS X Terminal lines don’t go into scrollback

This means that the terminal is using the alternate screen buffer. There is a main screen, which scrolls into the scrollback log, and an alternate screen that does not. “Full screen” or “screen-oriented” programs like top, less, emacs, vim and screen switch the terminal to the alternate screen by default.

Each screen has its own contents and state. Having an alternate screen enables programs to take over the entire display, then restore the previous contents when they exit, by switching back to the main screen.

As of Mac OS X Lion 10.7, Terminal has a menu item you can use to manually switch screens:

View > Show/Hide Alternate Screen

This is provided primarily so that you can view or copy text from the alternate screen after a “full screen” program exits. Xterm has a similar command.

You can also use it to manually force a program to use a particular screen, to control whether the output goes to the scrollback log, for example. However, if you’re currently using a program that explicitly switches to the alternate screen, you may confuse it or get unexpected results if you force it to the main screen while the program is running, so use this with caution.

Depending on the program, it may have a command-line argument or some other means to configure it to use the main screen instead. e.g., less -X.

Some terminfo entries are specifically designed to suppress using the alternate screen, e.g., xterm1. TERM=xterm1 emacs will run Emacs on the main screen. I don’t recommend using xterm1 permanently, because it disables a number of other useful features compared to the default xterm-256color on Lion.

You can also switch screens using the tput command to issue the escape sequences from inside a shell or script. tput smcup switches to the alternate screen, and tput rmcup switches back to the main screen.

To see which program is currently running, look at the program name displayed in the Terminal window or tab title, or look at the Inspector window (Shell > Show Inspector). The last process in the list in the Inspector is (usually) the current program using the screen. That’s the one you’ll need to configure to use the main screen instead.

Leave a Comment