Apple's Terminal.app sets a TERM_PROGRAM environment variable to "Apple_Terminal". This gives us a good way to detect at runtime whether or not the terminal supports more than 8 colors.
The main reason for checking at runtime is that Mac users are able to run other terminal apps (xterm, rxvt, etc), and should expect to see more than 8 colors in terminals that support it.
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
TZVEM65VHVUXW3XWCXYGLL6VJJYUW4YXHRRTJHQYCJKD2QPVWWRAC
ZMDWMRPYXXYXWETOQANNKZ4RMP4LHZENRPVOYOE7ZU4HBZFUK64QC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
2BVS4A7OUZK3KNUYCWQSISSM36GJR2GX6KXZK62K5DPPNNCNXGKAC
22RFWMSJGG26Z2MQEEXGKVTFSTLREHQIG46WYOTMDRKI5YVMRNVAC
#ifdef USE_8_COLOUR_TERM_MAP
for (int i = 0; i < 16; i++)
colour[i] = i % 8;
// If USE_8_COLOUR_TERM_MAP is defined, then we force 8 colors.
// Otherwise, do a check to see if we're using Apple_Terminal.
#ifndef USE_8_COLOUR_TERM_MAP
if (strcmp(getenv("TERM_PROGRAM"), "Apple_Terminal") == 0) {
#endif
for (int i = 0; i < 16; i++)
colour[i] = i % 8;
colour[ DARKGREY ] = COL_TO_REPLACE_DARKGREY;
#else
for (int i = 0; i < 16; i++)
colour[i] = i;
colour[ DARKGREY ] = COL_TO_REPLACE_DARKGREY;
#ifndef USE_8_COLOUR_TERM_MAP
} else {
for (int i = 0; i < 16; i++)
colour[i] = i;
}