ANSI Colorized Terminal?

I have been trying and trying to get Terminal.app under SL to show colorized text highlighting and I just can't seem to get it to work correctly at all. I have read all kinds of conflicting information on the internet about it. Does anyone know the final real answer for 10.6? I have been able to get Terminal to show colorized ls output, that was simple enough. But man pages should be showing bold text in slightly different color if ansi color was working properly... and never mind that the real reason I want color is so that I can use command line vim with colorized syntax highlighting...which no matter what I do...is simply not working. Also the python shell is supposed to show some color, and it doesn't.

I have heard one rumor that Apple is shipping an incorrect termcap? Does anyone know the real answer?

Mac OS X (10.5.4)

Posted on Sep 1, 2010 1:31 PM

Reply
13 replies

Sep 1, 2010 2:04 PM in response to Dewdman42

So what is your TERM environment variable?

echo $TERM

my value is set to xterm-color

For Vim, I have the following in my .vimrc because I use Vim on lots of different platforms and this bit of Vim code works everywhere:

if has("terminfo")
let &t_Co=8
let &t_Sf="e[3%p1%dm"
let &t_Sb="e[4%p1%dm"
else
let &t_Co=8
let &t_Sf="e[3%dm"
let &t_Sb="e[4%dm"
endif
if $TERM == "xterm-16color"
let &t_Co=16 " xterm-16color has 16 colors minimum.
endif

If you do not wish to have the above in your .vimrc, then you will have to either find a terminfo setting for your TERM environment variable, or provide a terminfo file that has all the correct color information.

As for other Unix commands, they do not generally spit out color by default, and frequently want a command line argument that tells them to use color. ls is just one example. grep --color is another example.

I also use lots of color in my terminal sessions by sending color escape sequences:

# -foreground- ----bold---- -underline-- --reverse--- -background-
# black e[30m e[30;1m e[30;4m e[30;7m e[40;fg;1m
# red e[31m e[31;1m e[31;4m e[31;7m e[41;fg;1m
# green e[32m e[32;1m e[32;4m e[32;7m e[42;fg;1m
# yellow e[33m e[33;1m e[33;4m e[33;7m e[43;fg;1m
# blue e[34m e[34;1m e[34;4m e[34;7m e[44;fg;1m
# magenta e[35m e[35;1m e[35;4m e[35;7m e[45;fg;1m
# cyan e[36m e[36;1m e[36;4m e[36;7m e[46;fg;1m
# White e[37m e[37;1m e[37;4m e[37;7m e[47;fg;1m
#
# light black e[90m e[90;1m e[90;4m e[90;7m e[100;fg;1m
# light red e[91m e[91;1m e[91;4m e[91;7m e[101;fg;1m
# light green e[92m e[92;1m e[92;4m e[92;7m e[102;fg;1m
# light yellow e[93m e[93;1m e[93;4m e[93;7m e[103;fg;1m
# light blue e[94m e[94;1m e[94;4m e[94;7m e[104;fg;1m
# light magenta e[95m e[95;1m e[95;4m e[95;7m e[105;fg;1m
# light cyan e[96m e[96;1m e[96;4m e[96;7m e[106;fg;1m
# light White e[97m e[97;1m e[97;4m e[97;7m e[107;fg;1m
#
# Reset e[0m

where the 'light' colors only apply to a terminal that supports 16 colors (iTerm is one that does).

Sep 1, 2010 2:11 PM in response to Dewdman42

If you want to examine what your terminfo file (associated with your TERM) setting, you can use:

infocmp $TERM

You can use "man terminfo" to figure out what all the 'infocmp' output means.

For color information you want to look for 'Co' or 'colors' or 'max_colors' fields.

If you capture the 'infocmp' output and modify it, you can then compile a new version using 'tic' (see "man tic").

Sep 1, 2010 2:20 PM in response to BobHarris

My TERM has been set to xterm-color.

Bingo, that seemed to do it!

For the sake of learning, can you please tell me what these escape sequences are and how they tell VIM to do the right thing?

I'm wondering if it makes more sense to fix the termcap, if that is needed, so that some other things which might ordinarily use color, might also. I understand that most command line tools don't. Some do. For example, the python shell is supposed to use color. manpages can use a little color in addition to bold on key words. Just a few little things. Do you know what would be involved in fixing the underlying termcap database? I'm not afraid of root, but I've never understood how TERMCAP or TERMINFO work.

Am I to understand also that Terminal.app only supports xterm-color (8 colors)? Is that a limitation of Terminal or a limitation of the termcap that shipped with OSX?

Sep 1, 2010 3:06 PM in response to Dewdman42

For the sake of learning, can you please tell me what these escape sequences are and how they tell VIM to do the right thing?

Since I work on so many different platforms (Mac OS X, Linux, Solaris, AIX, Tru64 UNIX, HP-UX, Windows), it is too much trouble trying to figure out getting a working terminfo TERM setting. I just use the .vimrc code I posted, and my Vim always has syntax coloring.
I'm wondering if it makes more sense to fix the termcap,

terminfo has replaced TERMCAP
if that is needed, so that some other things which might ordinarily use color, might also. I understand that most command line tools don't. Some do. For example, the python shell is supposed to use color. manpages can use a little color in addition to bold on key words.
Just a few little things. Do you know what would be involved in fixing the underlying termcap database? I'm not afraid of root, but I've never understood how TERMCAP or TERMINFO work.

man infocmp
man tic
man terminfo
And this URL should give you information about most of the escape sequences an ANSI terminal accepts:
<http://www.tru64unix.compaq.com/docs/base doc/DOCUMENTATION/V51B_HTML/MAN/MAN5/0201___.HTM>

And if you figure out a new and improved xterm-color terminfo file, then I would suggest you post your improved file at:

BugReporter
<http://bugreporter.apple.com>
Free ADC (Apple Developer Connection) account needed for BugReporter.
Anyone can get a free account at:
<http://developer.apple.com/programs/register/>

Am I to understand also that Terminal.app only supports xterm-color (8 colors)? Is that a limitation of Terminal or a limitation of the termcap that shipped with OSX?

I think Terminal.app might support 16 colors, but only in the light vs dark range, not unique colors. That is to say dark red vs light red.

If you Google search for "16colors.sh" you will most likely find a script that will display the available 16 colors and you can judge for yourself.

iTerm also support 16 colors (the same dark vs light shades of the same 8 colors).

Message was edited by: BobHarris

Sep 2, 2010 2:49 PM in response to BobHarris

The ncurses terminfo entries for "nsterm" and similar names are
supposed to be the best match for Terminal.app; to see some of
the differences do "infocmp nsterm xterm-color".

Terminal.app might be closer to xterm than dtterm (aside from
the lack of the "bce" capability). In that case, a better place
to look for escape sequences would be in xterm's documentation,
e.g.,
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Sep 2, 2010 3:36 PM in response to BobHarris

My shell-account access to Usenet died a couple of years ago,
(the providers didn't keep it working), and though I have
a giganews account, haven't spent the time to fix that. So
I've been doing followups via Google where I see some information
is needed. (I've been "here" for a few years, originally iirc
to get information for tin 😉

Sep 2, 2010 3:59 PM in response to tedickey

Terminal.app might be closer to xterm than dtterm (aside from
the lack of the "bce" capability). In that case, a better place
to look for escape sequences would be in xterm's documentation,
e.g.,
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Yea, but since I worked for Digital Equipment corporation and the first time I found escape sequences from in VT**0 manuals and then on-line in the dtterm man page, I keep gravitating back to that. Mostly it works for me, as I rarely do anything fancy with escape sequences.

But I have bookmarked the invisible-island link and hopefully will use it more often.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

ANSI Colorized Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.