What terminal is the Mountain Lion Terminal app emulating?

Solution 1:

As with many terminal emulators, Terminal emulates most of a VT100 plus some features from newer terminals, and some common extensions from xterm and other emulators.

There is no terminfo file that exactly corresponds to Terminal, but the closest match used to be xterm-color, which represents an older offshoot of xterm. However, in recent versions Terminal is more fully compatible with xterm and xterm-256color is the new default value for the TERM environment variable.

In Preferences > Settings > [profile] > Advanced > Emulation there is a popup menu Declare terminal as: that sets the value of TERM (and that's all it does—it does not alter which features Terminal supports). If you're using a Mac that you've upgraded from an older OS version, you may want/need to update the setting to match the new recommended default if it is still set to xterm-color. Using xterm-color is not recommended and it is possible for it to cause problems because it isn't as close a match to Terminal's current feature set.

Despite the fact that installations of ncurses should include all terminfo files, some Linux distros do not, and in particular some of them omit xterm-256color. If this is the case you'll see programs complain in various ways about not being able to find it, and the solution is to install the entire set of terminfo files, or at least all the xterm ones.

If xterm-256color isn't available, the next best thing is xterm-16color, followed by xterm. These three are compatible and represent the current xterm version with decreasing numbers of supported colors (xterm only declares the eight basic ANSI colors, though a lot of programs simply ignore that and assume that sixteen are supported, but xterm-16color is the one to choose if you want to explicitly declare support for sixteen colors).

It's difficult to say exactly what could be causing the problem you're seeing, but the first thing to try is to run the infocmp command on the remote host to see what it says. That will tell you which terminfo it is expecting and whether it was found.

If it's a generic ncurses or terminfo issue, it's likely to occur with other programs, like vim. You might try running vim or less, for example, to compare behaviors. If you're feeling motivated, you could run vttest http://invisible-island.net/vttest/ on the remote host and check that Terminal responds appropriately to the tests for drawing text attributes, resizing the display, and switching to/from the alternate screen.

When you resize a terminal window, the terminal program notifies the tty device, which sends a SIGWINCH signal to processes connected to it. Programs are responsible for responding to the signal appropriately. One thing to test is whether the LINES and COLUMNS variables get updated in bash when you resize the terminal window. If that's working, then the signal mechanism is behaving correctly.

Another possibility is that the program isn't switching to/from the alternate screen correctly (which could be caused by having an incompatible terminfo selected). You can check the View > Hide/Show Alternate Screen menu item to see which screen is currently active. If it's showing the wrong screen, you might try manually switching it with the menu item and see if that clears up the problem.