diff --git a/src/Color.cpp b/src/Color.cpp index 5bf33a486..3990afe3e 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -348,6 +348,9 @@ Color::operator int () const void Color::blend (const Color& other) { #ifdef FEATURE_COLOR + if (!other.nontrivial ()) + return; + Color c (other); _value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline. _value |= (c._value & _COLOR_INVERSE); // Always inherit inverse. @@ -443,7 +446,7 @@ void Color::upgrade () std::string Color::colorize (const std::string& input) { #ifdef FEATURE_COLOR - if (_value == 0) + if (!nontrivial ()) return input; int count = 0; @@ -486,7 +489,7 @@ std::string Color::colorize (const std::string& input) } // 16 color - if (_value != 0) + else { result << "\033["; @@ -570,7 +573,7 @@ std::string Color::colorize (const std::string& input, const std::string& spec) } //////////////////////////////////////////////////////////////////////////////// -bool Color::nontrivial () +bool Color::nontrivial () const { return _value != 0 ? true : false; } diff --git a/src/Color.h b/src/Color.h index f92e619e2..a16c7af59 100644 --- a/src/Color.h +++ b/src/Color.h @@ -66,7 +66,7 @@ public: static std::string colorize (const std::string&, const std::string&); static std::string strip (const std::string&); - bool nontrivial (); + bool nontrivial () const; private: int find (const std::string&); diff --git a/src/rules.cpp b/src/rules.cpp index 33b03ce63..0bff3450f 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -134,31 +134,35 @@ static void colorizePriorityNone (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeActive (Task& task, const std::string& rule, Color& c) { - if (gsColor[rule].nontrivial () && - task.has ("start") && - !task.has ("end")) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.has ("start") && + !task.has ("end")) + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeScheduled (Task& task, const std::string& rule, Color& c) { - if (gsColor[rule].nontrivial () && - task.has ("scheduled") && - Date (task.get_date ("scheduled")) <= now) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.has ("scheduled") && + Date (task.get_date ("scheduled")) <= now) + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeTag (Task& task, const std::string& rule, Color& c) { - if (task.hasTag (rule.substr (10))) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.hasTag (rule.substr (10))) + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeProject (Task& task, const std::string& rule, Color& c) { + if (!gsColor[rule].nontrivial ()) + return; + // Observe the case sensitivity setting. bool sensitive = context.config.getBoolean ("search.case.sensitive"); @@ -174,20 +178,25 @@ static void colorizeProject (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeProjectNone (Task& task, const std::string& rule, Color& c) { - if (task.get ("project") == "") - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.get ("project") == "") + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeTagNone (Task& task, const std::string& rule, Color& c) { - if (task.getTagCount () == 0) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.getTagCount () == 0) + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeKeyword (Task& task, const std::string& rule, Color& c) { + if (!gsColor[rule].nontrivial ()) + return; + // Observe the case sensitivity setting. bool sensitive = context.config.getBoolean ("search.case.sensitive"); @@ -216,6 +225,9 @@ static void colorizeKeyword (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeDue (Task& task, const std::string& rule, Color& c) { + if (!gsColor[rule].nontrivial ()) + return; + Task::status status = task.getStatus (); if (task.has ("due") && @@ -230,6 +242,9 @@ static void colorizeDue (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeDueToday (Task& task, const std::string& rule, Color& c) { + if (!gsColor[rule].nontrivial ()) + return; + Task::status status = task.getStatus (); if (task.has ("due") && @@ -244,6 +259,9 @@ static void colorizeDueToday (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeOverdue (Task& task, const std::string& rule, Color& c) { + if (!gsColor[rule].nontrivial ()) + return; + Task::status status = task.getStatus (); if (task.has ("due") && @@ -266,15 +284,17 @@ static void colorizeRecurring (Task& task, const std::string& rule, Color& c) //////////////////////////////////////////////////////////////////////////////// static void colorizeCompleted (Task& task, const std::string& rule, Color& c) { - if (task.getStatus () == Task::completed) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.getStatus () == Task::completed) + c.blend (gsColor[rule]); } //////////////////////////////////////////////////////////////////////////////// static void colorizeDeleted (Task& task, const std::string& rule, Color& c) { - if (task.getStatus () == Task::completed) - c.blend (gsColor[rule]); + if (gsColor[rule].nontrivial ()) + if (task.getStatus () == Task::completed) + c.blend (gsColor[rule]); } ////////////////////////////////////////////////////////////////////////////////