From fa9a5721b1e903f5e2435d928183621071d45cc4 Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Mon, 12 Oct 2009 13:48:08 -0700 Subject: 8 color terminals: switch to conditional usage based on terminal type 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 --- crawl-ref/source/initfile.cc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/initfile.cc') diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 2a796af899..a5b1a86a72 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -961,14 +961,20 @@ void game_options::reset_options() #endif // map each colour to itself as default -#ifdef USE_8_COLOUR_TERM_MAP - 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; + // 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; +#ifndef USE_8_COLOUR_TERM_MAP + } else { + for (int i = 0; i < 16; i++) + colour[i] = i; + } #endif // map each channel to plain (well, default for now since I'm testing) -- cgit v1.2.3-54-g00ecf