mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Check systematically if the color is non-trivial before blending.
This commit is contained in:
parent
f2f6b788e8
commit
90c420263c
3 changed files with 45 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -134,8 +134,8 @@ 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") &&
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.has ("start") &&
|
||||
!task.has ("end"))
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -143,8 +143,8 @@ static void colorizeActive (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeScheduled (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial () &&
|
||||
task.has ("scheduled") &&
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.has ("scheduled") &&
|
||||
Date (task.get_date ("scheduled")) <= now)
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ static void colorizeScheduled (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeTag (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.hasTag (rule.substr (10)))
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -159,6 +160,9 @@ static void colorizeTag (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.
|
||||
bool sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||
|
||||
|
@ -174,6 +178,7 @@ static void colorizeProject (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeProjectNone (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.get ("project") == "")
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -181,6 +186,7 @@ static void colorizeProjectNone (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeTagNone (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.getTagCount () == 0)
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -188,6 +194,9 @@ static void colorizeTagNone (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.
|
||||
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,6 +284,7 @@ static void colorizeRecurring (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeCompleted (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.getStatus () == Task::completed)
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
@ -273,6 +292,7 @@ static void colorizeCompleted (Task& task, const std::string& rule, Color& c)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void colorizeDeleted (Task& task, const std::string& rule, Color& c)
|
||||
{
|
||||
if (gsColor[rule].nontrivial ())
|
||||
if (task.getStatus () == Task::completed)
|
||||
c.blend (gsColor[rule]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue