Index: src/Output.hh =================================================================== --- src/Output.hh (revision 39) +++ src/Output.hh (working copy) @@ -77,6 +77,8 @@ COLM_ERROR, ///< color for debug output (CERR) }; + static void init(); + /// set the color mode (if colors_enabled). Outputs the escape sequence /// for \b mode when the color mode changes static void set_color_mode(ColorMode mode); @@ -93,21 +95,18 @@ /// true if the print semaphore was acquired static bool print_sema_held; - /// escape sequences for CIN colors - static char color_CIN[21]; + /// chosen colours for CIN colours + static int color_CIN_foreground; + static int color_CIN_background; - /// escape sequences for COUT colors - static char color_COUT[21]; + /// chosen colours for COUT colours + static int color_COUT_foreground; + static int color_COUT_background; - /// escape sequences for CERR colors - static char color_CERR[21]; + /// chosen colours for CERR colours + static int color_CERR_foreground; + static int color_CERR_background; - /// escape sequences for resetting colors - static char color_RESET[21]; - - /// escape sequences for clear to end of line - static char clear_EOL[21]; - protected: /// the current color mode static ColorMode color_mode; Index: src/main.cc =================================================================== --- src/main.cc (revision 39) +++ src/main.cc (working copy) @@ -62,6 +62,8 @@ getrlimit(RLIMIT_AS, &rl); total_memory = rl.rlim_cur; + Output::init(); + Avec::init(); LibPaths::init(argv0); Value::init(); @@ -679,31 +681,6 @@ { Log_control(LogId(d[0]), true); } - else if (!strcasecmp(opt, "CIN-SEQUENCE")) - { - loop(p, count - 1) Output::color_CIN[p] = (char)(d[p] & 0xFF); - Output::color_CIN[count - 1] = 0; - } - else if (!strcasecmp(opt, "COUT-SEQUENCE")) - { - loop(p, count - 1) Output::color_COUT[p] = (char)(d[p] & 0xFF); - Output::color_COUT[count - 1] = 0; - } - else if (!strcasecmp(opt, "CERR-SEQUENCE")) - { - loop(p, count - 1) Output::color_CERR[p] = (char)(d[p] & 0xFF); - Output::color_CERR[count - 1] = 0; - } - else if (!strcasecmp(opt, "RESET-SEQUENCE")) - { - loop(p, count - 1) Output::color_RESET[p] = (char)(d[p] & 0xFF); - Output::color_RESET[count - 1] = 0; - } - else if (!strcasecmp(opt, "CLEAR-EOL-SEQUENCE")) - { - loop(p, count - 1) Output::clear_EOL[p] = (char)(d[p] & 0xFF); - Output::clear_EOL[count - 1] = 0; - } else if (!strncasecmp(opt, "LIBREF-", 7)) { const int lib_ref = atoi(opt + 7); Index: src/Output.cc =================================================================== --- src/Output.cc (revision 39) +++ src/Output.cc (working copy) @@ -18,6 +18,9 @@ along with this program. If not, see . */ +#include +#include + #include "Command.hh" #include "Common.hh" #include "DiffOut.hh" @@ -27,6 +30,15 @@ #include "Svar_DB.hh" #include "TestFiles.hh" +int Output::color_CIN_foreground = 0; +int Output::color_CIN_background = 7; + +int Output::color_COUT_foreground = -1; +int Output::color_COUT_background = -1; + +int Output::color_CERR_foreground = 4; +int Output::color_CERR_background = 7; + bool Output::colors_enabled = false; bool Output::print_sema_held = false; @@ -77,21 +89,6 @@ Output::ColorMode Output::color_mode = COLM_UNDEF; -/// VT100 escape sequence to turn cin color on -char Output::color_CIN[21] = { CIN_COLOR_WANTED, 0 }; // from config.h - -/// VT100 escape sequence to turn cout color on -char Output::color_COUT[21] = { COUT_COLOR_WANTED, 0 }; // from config.h - -/// VT100 escape sequence to turn cerr color on -char Output::color_CERR[21] = { CERR_COLOR_WANTED, 0 }; // from config.h - -/// VT100 escape sequence to reset colors to their default -char Output::color_RESET[21] = { RESET_COLORS_WANTED, 0 }; // from config.h - -/// VT100 escape sequence to clear to end of line -char Output::clear_EOL[21] = { CLEAR_EOL_WANTED, 0 }; // from config.h - //----------------------------------------------------------------------------- int CinOut::overflow(int c) @@ -139,19 +136,62 @@ return 0; } //----------------------------------------------------------------------------- +static int +outputCharStdout(int ch) +{ + return fputc(ch, stdout); +} +//----------------------------------------------------------------------------- +static int +outputCharStderr(int ch) +{ + return fputc(ch, stderr); +} +//----------------------------------------------------------------------------- void +Output::init() +{ + int ret = setupterm(NULL, fileno(stdout), NULL); + if(ret != OK) + { + colors_enabled = false; + } +} +//----------------------------------------------------------------------------- +void Output::reset_dout() { dout_filebuf.reset(); } //----------------------------------------------------------------------------- +static void +updateColour(int foregroundValue, int backgroundValue, bool destinationIsStdout) +{ + int (*fn)(int) = destinationIsStdout ? outputCharStdout : outputCharStderr; + + if (foregroundValue == -1 || backgroundValue == -1) + { + tputs(exit_attribute_mode, 1, fn); + } + else + { + tputs(tparm(set_foreground, foregroundValue), 1, fn); + tputs(tparm(set_background, backgroundValue), 1, fn); + } + + tputs(clr_eol, 1, fn); +} +//----------------------------------------------------------------------------- void Output::reset_colors() { if (!colors_enabled) return; - cout << color_RESET << clear_EOL; - cerr << color_RESET << clear_EOL; + tputs(exit_attribute_mode, 1, outputCharStdout); + tputs(clr_eol, 1, outputCharStdout); + + tputs(exit_attribute_mode, 1, outputCharStderr); + tputs(clr_eol, 1, outputCharStderr); } //----------------------------------------------------------------------------- void @@ -163,9 +203,17 @@ { switch(color_mode = mode) { - case COLM_INPUT: cout << color_CIN << clear_EOL; break; - case COLM_OUTPUT: cout << color_COUT << clear_EOL; break; - case COLM_ERROR: cerr << color_CERR << clear_EOL; break; + case COLM_INPUT: + updateColour(color_CIN_foreground, color_CIN_background, true); + break; + + case COLM_OUTPUT: + updateColour(color_COUT_foreground, color_COUT_background, true); + break; + + case COLM_ERROR: + updateColour(color_CERR_foreground, color_CERR_background, false); + break; } } } Index: configure.ac =================================================================== --- configure.ac (revision 39) +++ configure.ac (working copy) @@ -158,33 +158,5 @@ AC_DEFINE_UNQUOTED([SHORT_VALUE_LENGTH_WANTED], [$SHORT_VALUE_LENGTH_WANTED], [short value cellcount]) -# APL: desired colors for CERR, CIN, and COUT ? -AC_ARG_VAR(CERR_COLOR_WANTED, - [ CERR color (see README-2-configure) default: CSI 0;35;47m ]) -AC_ARG_VAR(CIN_COLOR_WANTED, - [ CIN color (see README-2-configure) default: CSI 0;30;47m ]) -AC_ARG_VAR(COUT_COLOR_WANTED, - [ COUT color (see README-2-configure) default: CSI 0;30;48m ]) -AC_ARG_VAR(RESET_COLORS_WANTED, - [ reset colors (see README-2-configure) default: CSI 0;38;48m ]) -AC_ARG_VAR(CLEAR_EOL_WANTED, - [ clear to end-of-line (see README-2-configure) default: CSI K ]) -if test "x$CERR_COLOR_WANTED" = "x"; - then CERR_COLOR_WANTED="27, 91, '0', ';', '3', '5', ';', '4', '8', 'm'" ; fi -if test "x$CIN_COLOR_WANTED" = "x"; - then CIN_COLOR_WANTED="27, 91, '0', ';', '3', '0', ';', '4', '7', 'm'" ; fi -if test "x$COUT_COLOR_WANTED" = "x"; - then COUT_COLOR_WANTED="27, 91, '0', ';', '3', '0', ';', '4', '8', 'm'" ; fi -if test "x$RESET_COLORS_WANTED" = "x"; - then RESET_COLORS_WANTED="27, 91, '0', ';', '3', '8', ';', '4', '8', 'm'"; fi -if test "x$CLEAR_EOL_WANTED" = "x"; - then CLEAR_EOL_WANTED="27, 91, 'K'" ; fi - -AC_DEFINE_UNQUOTED([CERR_COLOR_WANTED], [$CERR_COLOR_WANTED], [CERR color]) -AC_DEFINE_UNQUOTED([CIN_COLOR_WANTED], [$CIN_COLOR_WANTED], [CIN color]) -AC_DEFINE_UNQUOTED([COUT_COLOR_WANTED], [$COUT_COLOR_WANTED], [COUT color]) -AC_DEFINE_UNQUOTED([RESET_COLORS_WANTED],[$RESET_COLORS_WANTED],[default color]) -AC_DEFINE_UNQUOTED([CLEAR_EOL_WANTED], [$CLEAR_EOL_WANTED], [clear to EOL]) - AC_OUTPUT