# HG changeset patch # User Teemu Piippo # Date 1437701078 -10800 # Node ID d301ead29d7c19d9ca7cf10d2dffd8f181252e9e # Parent f9f73eeba3b7b47c76968df73682589994e2f120 Apply Leonard's patch for fixing the colors: The colors were broken again. * isprint for some reason returned true when the given byte is higher than 255. The char cast of the byte was then printed which resulted in odd characters popping up. Black appeared as ^@ which is NULL in caret notation. * After that, the colors were all messed up because the RLINE enum didn't take in account the color swapping. So instead of messing up the enum order/number I went for a new "range-like" method. * After fixing all of that, I noticed the Interface::render_colorline had a broken loop since the VS2010 commits. This made the lines not print entierely and messed up the colors etc. diff -r f9f73eeba3b7 -r d301ead29d7c sources/coloredline.cpp --- a/sources/coloredline.cpp Fri Jul 24 00:43:16 2015 +0300 +++ b/sources/coloredline.cpp Fri Jul 24 04:24:38 2015 +0300 @@ -137,19 +137,8 @@ // void ColoredLine::set_color (Color a, bool on) { - switch (a) - { - case BLACK: m_data << (on ? RLINE_ON_BLACK : RLINE_OFF_BLACK); break; - case RED: m_data << (on ? RLINE_ON_RED : RLINE_OFF_RED); break; - case GREEN: m_data << (on ? RLINE_ON_GREEN : RLINE_OFF_GREEN); break; - case YELLOW: m_data << (on ? RLINE_ON_YELLOW : RLINE_OFF_YELLOW); break; - case BLUE: m_data << (on ? RLINE_ON_BLUE : RLINE_OFF_BLUE); break; - case MAGENTA: m_data << (on ? RLINE_ON_MAGENTA : RLINE_OFF_MAGENTA); break; - case CYAN: m_data << (on ? RLINE_ON_CYAN : RLINE_OFF_CYAN); break; - case WHITE: m_data << (on ? RLINE_ON_WHITE : RLINE_OFF_WHITE); break; - case NUM_COLORS: - case DEFAULT: assert (false); break; - } + assert (a < 8); + m_data << (a + (on ? RLINE_ON_COLOR : RLINE_OFF_COLOR)); } // ------------------------------------------------------------------------------------------------- diff -r f9f73eeba3b7 -r d301ead29d7c sources/coloredline.h --- a/sources/coloredline.h Fri Jul 24 00:43:16 2015 +0300 +++ b/sources/coloredline.h Fri Jul 24 04:24:38 2015 +0300 @@ -37,15 +37,15 @@ // of the enumerators based on their curses values. enum Color { - BLACK = COLOR_BLACK, - RED = COLOR_RED, - GREEN = COLOR_GREEN, - YELLOW = COLOR_YELLOW, - BLUE = COLOR_BLUE, - MAGENTA = COLOR_MAGENTA, - CYAN = COLOR_CYAN, - WHITE = COLOR_WHITE, - DEFAULT = 8, + BLACK = COLOR_BLACK, + RED = COLOR_RED, + GREEN = COLOR_GREEN, + YELLOW = COLOR_YELLOW, + BLUE = COLOR_BLUE, + MAGENTA = COLOR_MAGENTA, + CYAN = COLOR_CYAN, + WHITE = COLOR_WHITE, + DEFAULT = 8, NUM_COLORS }; @@ -53,24 +53,10 @@ // enum { - RLINE_ON_BLACK = 256, - RLINE_ON_RED, - RLINE_ON_GREEN, - RLINE_ON_YELLOW, - RLINE_ON_BLUE, - RLINE_ON_MAGENTA, - RLINE_ON_CYAN, - RLINE_ON_WHITE, - RLINE_ON_BOLD, - RLINE_OFF_BLACK, - RLINE_OFF_RED, - RLINE_OFF_GREEN, - RLINE_OFF_YELLOW, - RLINE_OFF_BLUE, - RLINE_OFF_MAGENTA, - RLINE_OFF_CYAN, - RLINE_OFF_WHITE, - RLINE_OFF_BOLD, + RLINE_ON_COLOR = 256, + RLINE_OFF_COLOR = 264, + RLINE_ON_BOLD = 272, + RLINE_OFF_BOLD }; // ------------------------------------------------------------------------------------------------- diff -r f9f73eeba3b7 -r d301ead29d7c sources/interface.cpp --- a/sources/interface.cpp Fri Jul 24 00:43:16 2015 +0300 +++ b/sources/interface.cpp Fri Jul 24 04:24:38 2015 +0300 @@ -260,7 +260,7 @@ { int x = x0; - for (int i = 0; i < line.length(); ++i) + for (int i = 0; i < line.data().size(); ++i) { int byte = line.data()[i]; @@ -273,35 +273,13 @@ ++y; } - if (isprint (byte)) + if (byte < 256 && isprint (byte)) { mvaddch (y, x, char (byte)); ++x; } else switch (byte) { - case RLINE_ON_BLACK: - case RLINE_ON_RED: - case RLINE_ON_GREEN: - case RLINE_ON_YELLOW: - case RLINE_ON_BLUE: - case RLINE_ON_MAGENTA: - case RLINE_ON_CYAN: - case RLINE_ON_WHITE: - attron (color_pair (Color (byte - RLINE_ON_BLACK), DEFAULT)); - break; - - case RLINE_OFF_BLACK: - case RLINE_OFF_RED: - case RLINE_OFF_GREEN: - case RLINE_OFF_YELLOW: - case RLINE_OFF_BLUE: - case RLINE_OFF_MAGENTA: - case RLINE_OFF_CYAN: - case RLINE_OFF_WHITE: - attroff (color_pair (Color (byte - RLINE_OFF_BLACK), DEFAULT)); - break; - case RLINE_ON_BOLD: attron (A_BOLD); break; @@ -309,6 +287,13 @@ case RLINE_OFF_BOLD: attroff (A_BOLD); break; + + default: + if (byte < 256) + break; + + (byte < RLINE_OFF_COLOR ? attron : attroff) (color_pair (Color ((byte - RLINE_ON_COLOR) & 7), DEFAULT)); + break; } }