From 2074c8bb27c60e5c240ab95390d69e0c7568413f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 22 Sep 2009 21:36:36 -0400 Subject: [PATCH] Feature - 256-color support - Fixed bug that caused \033[m sequences to be emitted when no color is specified, in 16-color mode. --- src/Color.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index e3b3f8a32..b16db5892 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -418,18 +418,35 @@ std::string Color::colorize (const std::string& input) // 256 color if (value & _COLOR_256) { + bool needTerminator = false; + if (value & _COLOR_UNDERLINE) + { result << "\033[4m"; + needTerminator = true; + } if (!(value & _COLOR_NOFG)) + { result << "\033[38;5;" << (value & _COLOR_FG) << "m"; + needTerminator = true; + } if (!(value & _COLOR_NOBG)) + { result << "\033[48;5;" << ((value & _COLOR_BG) >> 8) << "m"; + needTerminator = true; + } + + result << input; + if (needTerminator) + result << "\033[0m"; + + return result.str (); } // 16 color - else + if (value != (_COLOR_NOFG | _COLOR_NOBG)) { result << "\033["; @@ -457,11 +474,11 @@ std::string Color::colorize (const std::string& input) result << (29 + (value & _COLOR_FG)); } - result << "m"; + result << "m" << input << "\033[0m"; + return result.str (); } - result << input << "\033[0m"; - return result.str (); + return input; } ////////////////////////////////////////////////////////////////////////////////