From 087cf7e5edc58948da7694d9093f19412910ab06 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 13 Jun 2011 23:03:50 -0400 Subject: [PATCH] Feature #479 - Added filtering to the calendar command. --- ChangeLog | 1 + NEWS | 1 + src/commands/CmdCalendar.cpp | 27 +++++++++++++++++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 469997469..4f6b8e32f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ # Tracked Features, sorted by ID. + Added feature #330, which supports the 'inverse' color attribute. + + Added feature #479, which enables filtering for the 'calendar' command. + Added feature #523 & #659, adding 'status' as a reportable field (thanks to Peter De Poorter and Bryce Harrington). + Added feature #545, #610, #611, #646, which support complex aliases. diff --git a/NEWS b/NEWS index 1d23cbf76..96dfb276e 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,7 @@ New Features in taskwarrior 2.0.0 - JSON is the new default export format. - New 'reports' command that lists reports and their descriptions. - New complex aliases. + - Filtering now available on most read-only commands. Please refer to the ChangeLog file for full details. There are too many to list here. diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index 503808bb4..7231317a9 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,6 @@ int CmdCalendar::execute (std::string& output) { int rc = 0; -/* // Each month requires 28 text columns width. See how many will actually // fit. But if a preference is specified, and it fits, use it. int width = context.getWidth (); @@ -72,6 +72,16 @@ int CmdCalendar::execute (std::string& output) context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + Date today; bool getpendingdate = false; int monthsToDisplay = 1; @@ -115,6 +125,7 @@ int CmdCalendar::execute (std::string& output) int argMonth = 0; int argYear = 0; bool argWholeYear = false; +/* std::vector args = context.args.list (); std::vector ::iterator arg; for (arg = args.begin (); arg != args.end (); ++arg) @@ -154,6 +165,7 @@ int CmdCalendar::execute (std::string& output) else throw std::string ("Could not recognize argument '") + *arg + "'."; } +*/ // Supported combinations: // @@ -180,11 +192,11 @@ int CmdCalendar::execute (std::string& output) // Now begin the data subset and rendering. int countDueDates = 0; - if (getpendingdate == true) { + if (getpendingdate == true) + { // Find the oldest pending due date. Date oldest (12,31,2037); - std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { if (task->getStatus () == Task::pending) { @@ -277,7 +289,7 @@ int CmdCalendar::execute (std::string& output) out << "\n" << optionalBlankLine () - << renderMonths (mFrom, yFrom, today, tasks, monthsPerLine) + << renderMonths (mFrom, yFrom, today, filtered, monthsPerLine) << "\n"; mFrom += monthsPerLine; @@ -350,10 +362,6 @@ int CmdCalendar::execute (std::string& output) // Display all due task in the report colorized not only the imminet ones context.config.set ("due", 0); - context.args.clear (); - context.filter.clear (); - context.sequence.clear (); - std::string output; context.commands[report]->execute (output); out << output; @@ -402,7 +410,6 @@ int CmdCalendar::execute (std::string& output) } output = out.str (); -*/ return rc; }