Code Cleanup

- Check systematically if the color is non-trivial before blending.
This commit is contained in:
Louis-Claude Canon 2012-05-27 12:03:19 +02:00 committed by Paul Beckingham
parent f2f6b788e8
commit 90c420263c
3 changed files with 45 additions and 22 deletions

View file

@ -348,6 +348,9 @@ Color::operator int () const
void Color::blend (const Color& other) void Color::blend (const Color& other)
{ {
#ifdef FEATURE_COLOR #ifdef FEATURE_COLOR
if (!other.nontrivial ())
return;
Color c (other); Color c (other);
_value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline. _value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline.
_value |= (c._value & _COLOR_INVERSE); // Always inherit inverse. _value |= (c._value & _COLOR_INVERSE); // Always inherit inverse.
@ -443,7 +446,7 @@ void Color::upgrade ()
std::string Color::colorize (const std::string& input) std::string Color::colorize (const std::string& input)
{ {
#ifdef FEATURE_COLOR #ifdef FEATURE_COLOR
if (_value == 0) if (!nontrivial ())
return input; return input;
int count = 0; int count = 0;
@ -486,7 +489,7 @@ std::string Color::colorize (const std::string& input)
} }
// 16 color // 16 color
if (_value != 0) else
{ {
result << "\033["; 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; return _value != 0 ? true : false;
} }

View file

@ -66,7 +66,7 @@ public:
static std::string colorize (const std::string&, const std::string&); static std::string colorize (const std::string&, const std::string&);
static std::string strip (const std::string&); static std::string strip (const std::string&);
bool nontrivial (); bool nontrivial () const;
private: private:
int find (const std::string&); int find (const std::string&);

View file

@ -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) static void colorizeActive (Task& task, const std::string& rule, Color& c)
{ {
if (gsColor[rule].nontrivial () && if (gsColor[rule].nontrivial ())
task.has ("start") && if (task.has ("start") &&
!task.has ("end")) !task.has ("end"))
c.blend (gsColor[rule]); c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeScheduled (Task& task, const std::string& rule, Color& c) static void colorizeScheduled (Task& task, const std::string& rule, Color& c)
{ {
if (gsColor[rule].nontrivial () && if (gsColor[rule].nontrivial ())
task.has ("scheduled") && if (task.has ("scheduled") &&
Date (task.get_date ("scheduled")) <= now) Date (task.get_date ("scheduled")) <= now)
c.blend (gsColor[rule]); c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeTag (Task& task, const std::string& rule, Color& c) static void colorizeTag (Task& task, const std::string& rule, Color& c)
{ {
if (task.hasTag (rule.substr (10))) if (gsColor[rule].nontrivial ())
c.blend (gsColor[rule]); if (task.hasTag (rule.substr (10)))
c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeProject (Task& task, const std::string& rule, Color& c) static void colorizeProject (Task& task, const std::string& rule, Color& c)
{ {
if (!gsColor[rule].nontrivial ())
return;
// Observe the case sensitivity setting. // Observe the case sensitivity setting.
bool sensitive = context.config.getBoolean ("search.case.sensitive"); 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) static void colorizeProjectNone (Task& task, const std::string& rule, Color& c)
{ {
if (task.get ("project") == "") if (gsColor[rule].nontrivial ())
c.blend (gsColor[rule]); if (task.get ("project") == "")
c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeTagNone (Task& task, const std::string& rule, Color& c) static void colorizeTagNone (Task& task, const std::string& rule, Color& c)
{ {
if (task.getTagCount () == 0) if (gsColor[rule].nontrivial ())
c.blend (gsColor[rule]); if (task.getTagCount () == 0)
c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeKeyword (Task& task, const std::string& rule, Color& c) static void colorizeKeyword (Task& task, const std::string& rule, Color& c)
{ {
if (!gsColor[rule].nontrivial ())
return;
// Observe the case sensitivity setting. // Observe the case sensitivity setting.
bool sensitive = context.config.getBoolean ("search.case.sensitive"); 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) static void colorizeDue (Task& task, const std::string& rule, Color& c)
{ {
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus (); Task::status status = task.getStatus ();
if (task.has ("due") && 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) static void colorizeDueToday (Task& task, const std::string& rule, Color& c)
{ {
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus (); Task::status status = task.getStatus ();
if (task.has ("due") && 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) static void colorizeOverdue (Task& task, const std::string& rule, Color& c)
{ {
if (!gsColor[rule].nontrivial ())
return;
Task::status status = task.getStatus (); Task::status status = task.getStatus ();
if (task.has ("due") && 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) static void colorizeCompleted (Task& task, const std::string& rule, Color& c)
{ {
if (task.getStatus () == Task::completed) if (gsColor[rule].nontrivial ())
c.blend (gsColor[rule]); if (task.getStatus () == Task::completed)
c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void colorizeDeleted (Task& task, const std::string& rule, Color& c) static void colorizeDeleted (Task& task, const std::string& rule, Color& c)
{ {
if (task.getStatus () == Task::completed) if (gsColor[rule].nontrivial ())
c.blend (gsColor[rule]); if (task.getStatus () == Task::completed)
c.blend (gsColor[rule]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////