mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancements - rules.cpp
- Converted rules.cpp to work under 1.8.0. - Relocated validReportColumns, validSortColumns to parse.cpp.
This commit is contained in:
parent
ac9dae9af8
commit
66011acbf8
5 changed files with 91 additions and 92 deletions
|
@ -42,6 +42,8 @@ bool validPriority (const std::string&);
|
|||
bool validDate (std::string&);
|
||||
bool validDuration (std::string&);
|
||||
bool validDescription (const std::string&);
|
||||
void validReportColumns (const std::vector <std::string>&);
|
||||
void validSortColumns (const std::vector <std::string>&, const std::vector <std::string>&);
|
||||
|
||||
// task.cpp
|
||||
void gatherNextTasks (/*const TDB&,*/ T&, std::vector <T>&, std::vector <int>&);
|
||||
|
@ -101,14 +103,11 @@ std::string handleReportActive ();
|
|||
std::string handleReportOverdue ();
|
||||
std::string handleReportStats ();
|
||||
std::string handleReportTimesheet ();
|
||||
|
||||
std::string handleCustomReport (const std::string&);
|
||||
void validReportColumns (const std::vector <std::string>&);
|
||||
void validSortColumns (const std::vector <std::string>&, const std::vector <std::string>&);
|
||||
|
||||
// rules.cpp
|
||||
void initializeColorRules ();
|
||||
void autoColorize (T&, Text::color&, Text::color&);
|
||||
void autoColorize (Task&, Text::color&, Text::color&);
|
||||
|
||||
// import.cpp
|
||||
std::string handleImport ();
|
||||
|
|
|
@ -424,6 +424,7 @@ bool validDuration (std::string& input)
|
|||
// | \d+ "-" \d+ ;
|
||||
//
|
||||
// description (whatever isn't one of the above)
|
||||
/*
|
||||
void parse (
|
||||
std::vector <std::string>& args,
|
||||
std::string& command,
|
||||
|
@ -552,6 +553,66 @@ void parse (
|
|||
if (validDescription (descCandidate))
|
||||
task.setDescription (descCandidate);
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validReportColumns (const std::vector <std::string>& columns)
|
||||
{
|
||||
std::vector <std::string> bad;
|
||||
|
||||
std::vector <std::string>::const_iterator it;
|
||||
for (it = columns.begin (); it != columns.end (); ++it)
|
||||
if (*it != "id" &&
|
||||
*it != "uuid" &&
|
||||
*it != "project" &&
|
||||
*it != "priority" &&
|
||||
*it != "entry" &&
|
||||
*it != "start" &&
|
||||
*it != "due" &&
|
||||
*it != "age" &&
|
||||
*it != "age_compact" &&
|
||||
*it != "active" &&
|
||||
*it != "tags" &&
|
||||
*it != "recur" &&
|
||||
*it != "recurrence_indicator" &&
|
||||
*it != "tag_indicator" &&
|
||||
*it != "description_only" &&
|
||||
*it != "description")
|
||||
bad.push_back (*it);
|
||||
|
||||
if (bad.size ())
|
||||
{
|
||||
std::string error;
|
||||
join (error, ", ", bad);
|
||||
throw std::string ("Unrecognized column name: ") + error;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validSortColumns (
|
||||
const std::vector <std::string>& columns,
|
||||
const std::vector <std::string>& sortColumns)
|
||||
{
|
||||
std::vector <std::string> bad;
|
||||
std::vector <std::string>::const_iterator sc;
|
||||
for (sc = sortColumns.begin (); sc != sortColumns.end (); ++sc)
|
||||
{
|
||||
std::vector <std::string>::const_iterator co;
|
||||
for (co = columns.begin (); co != columns.end (); ++co)
|
||||
if (sc->substr (0, sc->length () - 1) == *co)
|
||||
break;
|
||||
|
||||
if (co == columns.end ())
|
||||
bad.push_back (*sc);
|
||||
}
|
||||
|
||||
if (bad.size ())
|
||||
{
|
||||
std::string error;
|
||||
join (error, ", ", bad);
|
||||
throw std::string ("Sort column is not part of the report: ") + error;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ int getDueState (const std::string& due)
|
|||
if (dt < midnight)
|
||||
return 2;
|
||||
|
||||
Date nextweek = midnight + 7 * 86400;
|
||||
Date nextweek = midnight + context.config.get ("due", 7) * 86400;
|
||||
if (dt < nextweek)
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -3034,63 +3034,4 @@ std::string handleCustomReport (const std::string& report)
|
|||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validReportColumns (const std::vector <std::string>& columns)
|
||||
{
|
||||
std::vector <std::string> bad;
|
||||
|
||||
std::vector <std::string>::const_iterator it;
|
||||
for (it = columns.begin (); it != columns.end (); ++it)
|
||||
if (*it != "id" &&
|
||||
*it != "uuid" &&
|
||||
*it != "project" &&
|
||||
*it != "priority" &&
|
||||
*it != "entry" &&
|
||||
*it != "start" &&
|
||||
*it != "due" &&
|
||||
*it != "age" &&
|
||||
*it != "age_compact" &&
|
||||
*it != "active" &&
|
||||
*it != "tags" &&
|
||||
*it != "recur" &&
|
||||
*it != "recurrence_indicator" &&
|
||||
*it != "tag_indicator" &&
|
||||
*it != "description_only" &&
|
||||
*it != "description")
|
||||
bad.push_back (*it);
|
||||
|
||||
if (bad.size ())
|
||||
{
|
||||
std::string error;
|
||||
join (error, ", ", bad);
|
||||
throw std::string ("Unrecognized column name: ") + error;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validSortColumns (
|
||||
const std::vector <std::string>& columns,
|
||||
const std::vector <std::string>& sortColumns)
|
||||
{
|
||||
std::vector <std::string> bad;
|
||||
std::vector <std::string>::const_iterator sc;
|
||||
for (sc = sortColumns.begin (); sc != sortColumns.end (); ++sc)
|
||||
{
|
||||
std::vector <std::string>::const_iterator co;
|
||||
for (co = columns.begin (); co != columns.end (); ++co)
|
||||
if (sc->substr (0, sc->length () - 1) == *co)
|
||||
break;
|
||||
|
||||
if (co == columns.end ())
|
||||
bad.push_back (*sc);
|
||||
}
|
||||
|
||||
if (bad.size ())
|
||||
{
|
||||
std::string error;
|
||||
join (error, ", ", bad);
|
||||
throw std::string ("Sort column is not part of the report: ") + error;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "T.h"
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
#include "main.h"
|
||||
|
||||
extern Context context;
|
||||
|
||||
|
@ -84,7 +85,7 @@ void initializeColorRules ()
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void autoColorize (
|
||||
T& task,
|
||||
Task& task,
|
||||
Text::color& fg,
|
||||
Text::color& bg)
|
||||
{
|
||||
|
@ -95,9 +96,7 @@ void autoColorize (
|
|||
if (gsFg["color.tagged"] != Text::nocolor ||
|
||||
gsBg["color.tagged"] != Text::nocolor)
|
||||
{
|
||||
std::vector <std::string> tags;
|
||||
task.getTags (tags);
|
||||
if (tags.size ())
|
||||
if (task.getTagCount ())
|
||||
{
|
||||
fg = gsFg["color.tagged"];
|
||||
bg = gsBg["color.tagged"];
|
||||
|
@ -108,7 +107,7 @@ void autoColorize (
|
|||
if (gsFg["color.pri.L"] != Text::nocolor ||
|
||||
gsBg["color.pri.L"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("priority") == "L")
|
||||
if (task.get ("priority") == "L")
|
||||
{
|
||||
fg = gsFg["color.pri.L"];
|
||||
bg = gsBg["color.pri.L"];
|
||||
|
@ -119,7 +118,7 @@ void autoColorize (
|
|||
if (gsFg["color.pri.M"] != Text::nocolor ||
|
||||
gsBg["color.pri.M"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("priority") == "M")
|
||||
if (task.get ("priority") == "M")
|
||||
{
|
||||
fg = gsFg["color.pri.M"];
|
||||
bg = gsBg["color.pri.M"];
|
||||
|
@ -130,7 +129,7 @@ void autoColorize (
|
|||
if (gsFg["color.pri.H"] != Text::nocolor ||
|
||||
gsBg["color.pri.H"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("priority") == "H")
|
||||
if (task.get ("priority") == "H")
|
||||
{
|
||||
fg = gsFg["color.pri.H"];
|
||||
bg = gsBg["color.pri.H"];
|
||||
|
@ -141,7 +140,7 @@ void autoColorize (
|
|||
if (gsFg["color.pri.none"] != Text::nocolor ||
|
||||
gsBg["color.pri.none"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("priority") == "")
|
||||
if (task.get ("priority") == "")
|
||||
{
|
||||
fg = gsFg["color.pri.none"];
|
||||
bg = gsBg["color.pri.none"];
|
||||
|
@ -152,7 +151,7 @@ void autoColorize (
|
|||
if (gsFg["color.active"] != Text::nocolor ||
|
||||
gsBg["color.active"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("start") != "")
|
||||
if (task.has ("start"))
|
||||
{
|
||||
fg = gsFg["color.active"];
|
||||
bg = gsBg["color.active"];
|
||||
|
@ -180,7 +179,7 @@ void autoColorize (
|
|||
if (it->first.substr (0, 14) == "color.project.")
|
||||
{
|
||||
std::string value = it->first.substr (14, std::string::npos);
|
||||
if (task.getAttribute ("project") == value)
|
||||
if (task.get ("project") == value)
|
||||
{
|
||||
fg = gsFg[it->first];
|
||||
bg = gsBg[it->first];
|
||||
|
@ -194,7 +193,7 @@ void autoColorize (
|
|||
if (it->first.substr (0, 14) == "color.keyword.")
|
||||
{
|
||||
std::string value = lowerCase (it->first.substr (14, std::string::npos));
|
||||
std::string desc = lowerCase (task.getDescription ());
|
||||
std::string desc = lowerCase (task.get ("description"));
|
||||
if (desc.find (value) != std::string::npos)
|
||||
{
|
||||
fg = gsFg[it->first];
|
||||
|
@ -204,25 +203,24 @@ void autoColorize (
|
|||
}
|
||||
|
||||
// Colorization of the due and overdue.
|
||||
std::string due = task.getAttribute ("due");
|
||||
if (due != "")
|
||||
if (task.has ("due"))
|
||||
{
|
||||
Date dueDate (::atoi (due.c_str ()));
|
||||
Date now;
|
||||
Date then (now + context.config.get ("due", 7) * 86400);
|
||||
|
||||
// Overdue
|
||||
if (dueDate < now)
|
||||
{
|
||||
fg = gsFg["color.overdue"];
|
||||
bg = gsBg["color.overdue"];
|
||||
}
|
||||
|
||||
// Imminent
|
||||
else if (dueDate < then)
|
||||
std::string due = task.get ("due");
|
||||
switch (getDueState (due))
|
||||
{
|
||||
case 1: // imminent
|
||||
fg = gsFg["color.due"];
|
||||
bg = gsBg["color.due"];
|
||||
break;
|
||||
|
||||
case 2: // overdue
|
||||
fg = gsFg["color.overdue"];
|
||||
bg = gsBg["color.overdue"];
|
||||
break;
|
||||
|
||||
case 0: // not due at all
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,7 +228,7 @@ void autoColorize (
|
|||
if (gsFg["color.recurring"] != Text::nocolor ||
|
||||
gsBg["color.recurring"] != Text::nocolor)
|
||||
{
|
||||
if (task.getAttribute ("recur") != "")
|
||||
if (task.has ("recur"))
|
||||
{
|
||||
fg = gsFg["color.recurring"];
|
||||
bg = gsBg["color.recurring"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue