From 3abce22f0cc454428a1733e9adcb0c86ed805774 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 18 Nov 2009 00:36:57 -0500 Subject: [PATCH] Bug Fix - color - Fixed bug that failed to upgrade from 16- to 256-color mode when a color like "black on rgb003" was parsed. --- src/Color.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index 85c3582a2..218306c4e 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -96,7 +96,8 @@ Color::Color (const std::string& spec) : value (0) { // By converting underscores to spaces, we inherently support the old "on_red" - // style of specifying background colors. + // style of specifying background colors. We consider underscores to be + // deprecated. std::string modifiable_spec = spec; std::replace (modifiable_spec.begin (), modifiable_spec.end (), '_', ' '); @@ -112,24 +113,10 @@ Color::Color (const std::string& spec) { word = lowerCase (trim (*it)); - if (word == "bold") - { - value |= _COLOR_BOLD; - value &= ~_COLOR_256; - } - else if (word == "bright") - { - value |= _COLOR_BRIGHT; - value &= ~_COLOR_256; - } - else if (word == "underline") - { - value |= _COLOR_UNDERLINE; - } - else if (word == "on") - { - bg = true; - } + if (word == "bold") value |= _COLOR_BOLD; + else if (word == "bright") value |= _COLOR_BRIGHT; + else if (word == "underline") value |= _COLOR_UNDERLINE; + else if (word == "on") bg = true; // X where X is one of black, red, blue ... else if ((index = find (word)) != -1) @@ -154,6 +141,8 @@ Color::Color (const std::string& spec) if (index < 0 || index > 23) throw std::string ("The color '") + *it + "' is not recognized."; + upgrade (); + if (bg) { value |= _COLOR_HASBG; @@ -185,6 +174,9 @@ Color::Color (const std::string& spec) throw std::string ("The color '") + *it + "' is not recognized."; index = 16 + r*36 + g*6 + b; + + upgrade (); + if (bg) { value |= _COLOR_HASBG; @@ -206,6 +198,8 @@ Color::Color (const std::string& spec) if (index < 0 || index > 255) throw std::string ("The color '") + *it + "' is not recognized."; + upgrade (); + if (bg) { value |= _COLOR_HASBG; @@ -327,7 +321,7 @@ void Color::blend (const Color& other) value |= (c.value & _COLOR_UNDERLINE); // Always inherit underline. // 16 <-- 16. - if (!(value & _COLOR_256) && + if (!(value & _COLOR_256) && !(c.value & _COLOR_256)) { value |= (c.value & _COLOR_BOLD); // Inherit bold. @@ -351,8 +345,8 @@ void Color::blend (const Color& other) } // Upgrade either color, if necessary. - if (!(value & _COLOR_256)) upgrade (); - if (!(value & _COLOR_256)) c.upgrade (); + if (!(value & _COLOR_256)) upgrade (); + if (!(c.value & _COLOR_256)) c.upgrade (); // 256 <-- 256. if (c.value & _COLOR_HASFG)