Mon, 11 Jan 2016 02:42:34 +0200
Improved the color handling a tad
sources/interface.cpp | file | annotate | diff | comparison | revisions |
--- a/sources/interface.cpp Mon Jan 11 02:26:23 2016 +0200 +++ b/sources/interface.cpp Mon Jan 11 02:42:34 2016 +0200 @@ -43,7 +43,10 @@ // chtype Interface::color_pair (Color fg, Color bg) { - return COLOR_PAIR (1 + (int (fg) * NUM_COLORS) + int (bg)); + if (fg == DEFAULT && bg == DEFAULT) + return 0; + else + return COLOR_PAIR (1 + (int (fg) * NUM_COLORS) + int (bg)); } // ------------------------------------------------------------------------------------------------- @@ -171,10 +174,9 @@ if (::has_colors()) { ::start_color(); - ::use_default_colors(); - - int defaultFg = (use_default_colors() == OK) ? -1 : COLOR_WHITE; - int defaultBg = (use_default_colors() == OK) ? -1 : COLOR_BLACK; + bool hasDefaultColors = ::use_default_colors(); + int defaultFg = (hasDefaultColors == OK) ? -1 : COLOR_WHITE; + int defaultBg = (hasDefaultColors == OK) ? -1 : COLOR_BLACK; // Initialize color pairs for (int i = 0; i < NUM_COLORS; ++i) @@ -184,14 +186,13 @@ int fg = (i == DEFAULT) ? defaultFg : i; int bg = (j == DEFAULT) ? defaultBg : j; - if (::init_pair (pairnum, fg, bg) == ERR) - print_warning ("Unable to initialize color pair %d (%d, %d)\n", pairnum, fg, bg); + if (fg != -1 || bg != -1) + { + if (::init_pair (pairnum, fg, bg) == ERR) + print_warning ("Unable to initialize color pair %d (%d, %d)\n", pairnum, fg, bg); + } } } - else - { - print_warning ("This terminal does not appear to support colors.\n"); - } render_full(); refresh(); @@ -932,7 +933,6 @@ va_start (args, fmtstr); print_to_console (TEXTCOLOR_BrightBlue); vprint (fmtstr, args); - print_to_console (TEXTCOLOR_Reset); va_end (args); } @@ -944,7 +944,6 @@ va_start (args, fmtstr); print_to_console (TEXTCOLOR_BrightYellow "-!- "); vprint (fmtstr, args); - print_to_console (TEXTCOLOR_Reset); va_end (args); } @@ -956,7 +955,6 @@ va_start (args, fmtstr); print_to_console (TEXTCOLOR_BrightRed "!!! "); vprint (fmtstr, args); - print_to_console (TEXTCOLOR_Reset); va_end (args); }