From e19f08793195b5b8f4469910e78fa3e730f12e74 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 2 Jun 2011 00:47:05 -0400 Subject: [PATCH] Refactor - Prepared CmdCustom for new command line processing code. --- src/Arguments.cpp | 6 ++++++ src/Arguments.h | 7 +++++++ src/Context.cpp | 25 ++++++++++++++----------- src/Context.h | 15 ++++++++------- src/commands/CmdCustom.cpp | 27 +++++++++++++++++++++++++-- 5 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/Arguments.cpp b/src/Arguments.cpp index fda217384..1028156cf 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -257,6 +257,12 @@ bool Arguments::extract_command ( return false; } +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::remove_command (const std::string& command) +{ +} + //////////////////////////////////////////////////////////////////////////////// // TODO void Arguments::extract_filter () diff --git a/src/Arguments.h b/src/Arguments.h index ffa10d3ce..ec370c8e6 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -49,6 +49,13 @@ public: std::string combine (); bool extract_command (const std::vector &, std::string&); + void remove_command (const std::string&); + +/* + void extract_read_only (command, filter); + void extract_write_commands (filter, command, mods); +*/ + void extract_filter (); void extract_modifications (); diff --git a/src/Context.cpp b/src/Context.cpp index 3b127705a..4df8ac596 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -63,6 +63,7 @@ Context::Context () , use_color (true) , verbosity_legacy (false) , inShadow (false) +, command ("") , terminal_width (0) , terminal_height (0) { @@ -128,6 +129,15 @@ void Context::initialize (int argc, const char** argv) // TODO Instantiate extension command objects. // TODO Instantiate default command object. + + // Create list of all command keywords. + std::vector keywords; + std::map ::iterator i; + for (i = commands.begin (); i != commands.end (); ++i) + keywords.push_back (i->first); + + args.extract_command (keywords, command); + // TODO Instantiate extension UDA objects. // TODO Instantiate extension format objects. @@ -207,18 +217,11 @@ int Context::dispatch (std::string &out) { Timer t ("Context::dispatch"); - updateXtermTitle (); - - // Create list of all command keywords. - std::vector keywords; - std::map ::iterator i; - for (i = commands.begin (); i != commands.end (); ++i) - keywords.push_back (i->first); - // Autocomplete args against keywords. - std::string command; - if (args.extract_command (keywords, command)) + if (command != "") { + updateXtermTitle (); + Command* c = commands[command]; // GC is invoked prior to running any command that displays task IDs. @@ -838,7 +841,7 @@ void Context::updateXtermTitle () { std::string title; join (title, " ", args); - std::cout << "]0;task " << title << "" << std::endl; + std::cout << "]0;task " << command << " " << title << "" << std::endl; } } diff --git a/src/Context.h b/src/Context.h index 1369cc6c9..c85a7f9a0 100644 --- a/src/Context.h +++ b/src/Context.h @@ -96,18 +96,18 @@ public: Directory extension_dir; Config config; - Filter filter; - Sequence sequence; - Subst subst; - Task task; + Filter filter; // TODO Obsolete + Sequence sequence; // TODO Obsolete + Subst subst; // TODO Obsolete + Task task; // TODO Obsolete TDB tdb; // TODO Obsolete TDB2 tdb2; - std::string commandLine; + std::string commandLine; // TODO Obsolete std::string file_override; std::string var_overrides; std::map aliases; - std::vector tagAdditions; - std::vector tagRemovals; + std::vector tagAdditions; // TODO Obsolete + std::vector tagRemovals; // TODO Obsolete Hooks hooks; DOM dom; @@ -123,6 +123,7 @@ public: bool inShadow; std::map commands; + std::string command; int terminal_width; int terminal_height; diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index ea00dda02..574f573f4 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -81,11 +81,13 @@ int CmdCustom::execute (const std::string&, std::string& output) split (sortOrder, reportSort, ','); validateSortColumns (sortOrder); +/* // Apply rc overrides. std::vector filterArgs; std::vector filteredArgs; split (filterArgs, reportFilter, ' '); // context.applyOverrides (filterArgs, filteredArgs); +*/ /* { @@ -108,17 +110,35 @@ int CmdCustom::execute (const std::string&, std::string& output) } */ - // Get all the tasks. + // Load the data. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); +// context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); // TODO No filter. context.tdb.commit (); context.tdb.unlock (); +/* // Filter sequence. if (context.sequence.size ()) context.filter.applySequence (tasks, context.sequence); +*/ + +//////////////////////////////////// + // TODO Create the filter + context.args.remove_command (_keyword); + + //std::vector filter_args; + //context.args.extract_filter (filter_args); + + // TODO Apply the filter + // Filter filter (context.args); + + // std::vector filtered; + // thing.eval (filtered, context.args, tasks); +//////////////////////////////////// // Sort the tasks. std::vector sequence; @@ -150,6 +170,7 @@ int CmdCustom::execute (const std::string&, std::string& output) } // How many lines taken up by table header? + // TODO Consider rc.verbose int table_header; if (context.color () && context.config.getBoolean ("fontunderline")) table_header = 1; // Underlining doesn't use extra line. @@ -162,6 +183,7 @@ int CmdCustom::execute (const std::string&, std::string& output) getLimits (_keyword, maxrows, maxlines); // Adjust for fluff in the output. + // TODO Consider rc.verbose if (maxlines) maxlines -= (context.verbose ("blank") ? 1 : 0) + table_header @@ -169,6 +191,7 @@ int CmdCustom::execute (const std::string&, std::string& output) + context.footnotes.size (); // Render. + // TODO Consider rc.verbose std::stringstream out; if (tasks.size ()) {