From 824cba71521e1cd6361f262211f4b709328d567f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 26 Feb 2012 17:01:13 -0500 Subject: [PATCH] Bugs #552, #863 - Fixed bug #552, where 'rc.verbose=off' suppressed warnings (thanks to Peter De Poorter). - Fixed bug #863, which suppressed report labels with rc.verbose=off (thanks to Michelle Crane). --- ChangeLog | 4 ++ src/Config.cpp | 13 +++--- src/Context.cpp | 86 ++++++++++++++++++++++++++++++++++---- src/Context.h | 2 + src/commands/CmdCustom.cpp | 18 ++++---- test/verbose.t | 4 +- 6 files changed, 101 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef457dfce..249269518 100644 --- a/ChangeLog +++ b/ChangeLog @@ -132,6 +132,8 @@ variable forces taskwarrior to never use the last column. + Fixed bugs #533 and #536, which prevented having correct paths for themes in .taskrc (thanks to Juergen Daubert) + + Fixed bug #552, where 'rc.verbose=off' suppressed warnings (thanks to Peter + De Poorter). + Fixed bug #594, which broke the 'all' report with a combination of bad regex handling and a formatting bug (thanks to Steve Rader). + Fixed bug #605, which gave misleading project completion percentages under @@ -240,6 +242,8 @@ + Fixed bug #860, which prevented lower-case priority values from being accepted (thanks to Michelle Crane). + Fixed bug #862, which suppressed feedback from the 'denotate' command. + + Fixed bug #863, which suppressed report labels with rc.verbose=off (thanks to + Michelle Crane). + Fixed bug #879, which mis-parsed escaped characters in the data file (thanks to Michelle Crane). + Fixed bug #880, which listed the wrong file paths for themes (thanks to Peter diff --git a/src/Config.cpp b/src/Config.cpp index 59b4244c7..5d1f86a19 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -79,8 +79,9 @@ std::string Config::_defaults = "\n" "# Miscellaneous\n" "verbose=yes # Provide maximal feedback\n" - "#verbose=no # Provide minimal feedback\n" - "#verbose=list # Comma-separated list. May contain any subset of:\n" + "#verbose=no # Provide regular feedback\n" + "#verbose=nothing # Provide no feedback\n" + "# # Comma-separated list. May contain any subset of:\n" "#verbose=blank,header,footnote,label,new-id,affected,edit,special\n" "confirmation=yes # Confirmation on delete, big changes\n" "annotations=full # Level of verbosity for annotations: full, sparse or none\n" @@ -654,15 +655,15 @@ const bool Config::getBoolean (const std::string& key) if ((*this).find (key) != (*this).end ()) { std::string value = lowerCase ((*this)[key]); - if (value == "t" || + if (value == "t" || // TODO Deprecate value == "true" || value == "1" || - value == "+" || + value == "+" || // TODO Deprecate value == "y" || value == "yes" || value == "on" || - value == "enable" || - value == "enabled") + value == "enable" || // TODO Deprecate + value == "enabled") // TODO Deprecate return true; } diff --git a/src/Context.cpp b/src/Context.cpp index c0cb1015c..5137133c3 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -179,15 +179,15 @@ int Context::initialize (int argc, const char** argv) hooks.trigger ("on-launch"); } - catch (const std::string& error) + catch (const std::string& message) { - footnote (error); + error (message); rc = 2; } catch (...) { - footnote (STRING_UNKNOWN_ERROR); + error (STRING_UNKNOWN_ERROR); rc = 3; } @@ -224,6 +224,18 @@ int Context::initialize (int argc, const char** argv) std::cout << *f << "\n"; } + // Dump all errors, non-maskable. + // Colorized as footnotes. + if (rc) + { + std::vector ::iterator e; + for (e = errors.begin (); e != errors.end (); ++e) + if (color ()) + std::cout << colorizeFootnote (*e) << "\n"; + else + std::cout << *e << "\n"; + } + timer_init.stop (); return rc; } @@ -270,15 +282,15 @@ int Context::run () debug (s.str ()); } - catch (const std::string& error) + catch (const std::string& message) { - footnote (error); + error (message); rc = 2; } catch (...) { - footnote (STRING_UNKNOWN_ERROR); + error (STRING_UNKNOWN_ERROR); rc = 3; } @@ -318,6 +330,15 @@ int Context::run () std::cout << *f << "\n"; } + // Dump all errors, non-maskable. + // Colorized as footnotes. + std::vector ::iterator e; + for (e = errors.begin (); e != errors.end (); ++e) + if (color ()) + std::cout << colorizeFootnote (*e) << "\n"; + else + std::cout << *e << "\n"; + hooks.trigger ("on-exit"); return rc; } @@ -402,17 +423,56 @@ bool Context::color () } //////////////////////////////////////////////////////////////////////////////// -// TODO Support verbosity levels. +// Support verbosity levels: +// +// rc.verbose=1 Show all feedback. +// rc.verbose=0 Show regular feedback. +// rc.verbose=nothing Show the absolute minimum. +// rc.verbose=one,two Show verbosity for 'one' and 'two' only. +// bool Context::verbose (const std::string& token) { if (! verbosity.size ()) { verbosity_legacy = config.getBoolean ("verbose"); split (verbosity, config.get ("verbose"), ','); + + // Regular feedback means almost everything. + if (!verbosity_legacy && + verbosity.size () == 1 && + verbosity[0] != "nothing" && + verbosity[0] != "blank" && // This list must be complete. + verbosity[0] != "header" && // + verbosity[0] != "footnote" && // + verbosity[0] != "label" && // + verbosity[0] != "new-id" && // + verbosity[0] != "affected" && // + verbosity[0] != "edit" && // + verbosity[0] != "special") // + { + verbosity.clear (); + + // This list emulates rc.verbose=off in version 1.9.4. + verbosity.push_back ("blank"); + verbosity.push_back ("footnote"); + verbosity.push_back ("label"); + verbosity.push_back ("new-id"); + verbosity.push_back ("affected"); + verbosity.push_back ("edit"); + verbosity.push_back ("special"); + } } - if (verbosity_legacy || - std::find (verbosity.begin (), verbosity.end (), token) != verbosity.end ()) + // rc.verbose=true|y|yes|1|on overrides all. + if (verbosity_legacy) + return true; + + // rc.verbose=nothing overrides all. + if (verbosity[0] == "nothing") + return false; + + // Specific token match. + if (std::find (verbosity.begin (), verbosity.end (), token) != verbosity.end ()) return true; return false; @@ -625,6 +685,13 @@ void Context::footnote (const std::string& input) footnotes.push_back (input); } +//////////////////////////////////////////////////////////////////////////////// +void Context::error (const std::string& input) +{ + if (input.length ()) + errors.push_back (input); +} + //////////////////////////////////////////////////////////////////////////////// void Context::debug (const std::string& input) { @@ -636,6 +703,7 @@ void Context::clearMessages () { headers.clear (); footnotes.clear (); + errors.clear (); debugMessages.clear (); } diff --git a/src/Context.h b/src/Context.h index 4baf5965b..be5b5b384 100644 --- a/src/Context.h +++ b/src/Context.h @@ -68,6 +68,7 @@ public: void header (const std::string&); // Header message sink void footnote (const std::string&); // Footnote message sink void debug (const std::string&); // Debug message sink + void error (const std::string&); // Error message sink - non-maskable void clearMessages (); void clear (); @@ -101,6 +102,7 @@ public: std::vector verbosity; std::vector headers; std::vector footnotes; + std::vector errors; std::vector debugMessages; /* bool inShadow; diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index d0d4aac49..325b1d1b7 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -129,11 +129,12 @@ int CmdCustom::execute (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. - else - table_header = 2; // Dashes use an extra line. + int table_header = 0; + if (context.verbose ("label")) + if (context.color () && context.config.getBoolean ("fontunderline")) + table_header = 1; // Underlining doesn't use extra line. + else + table_header = 2; // Dashes use an extra line. // Report output can be limited by rows or lines. int maxrows = 0; @@ -141,15 +142,13 @@ int CmdCustom::execute (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 - + context.footnotes.size () + + (context.verbose ("footnote") ? context.footnotes.size () : 0) + 1; // "X tasks shown ..." // Render. - // TODO Consider rc.verbose std::stringstream out; if (filtered.size ()) { @@ -174,7 +173,8 @@ int CmdCustom::execute (std::string& output) out << ", " << format (STRING_CMD_CUSTOM_TRUNCATED, maxlines - table_header); - out << "\n"; + if (context.verbose ("affected")) + out << "\n"; } else { diff --git a/test/verbose.t b/test/verbose.t index e5a41fad5..a02f00f7b 100755 --- a/test/verbose.t +++ b/test/verbose.t @@ -43,7 +43,7 @@ if (open my $fh, '>', 'verbose.rc') my $output = qx{../src/task rc:verbose.rc rc.verbose:new-id add Sample1}; like ($output, qr/Created task \d/, '\'new-id\' verbosity good'); -$output = qx{../src/task rc:verbose.rc rc.verbose:off add Sample2}; +$output = qx{../src/task rc:verbose.rc rc.verbose:nothing add Sample2}; unlike ($output, qr/Created task \d/, '\'new-id\' verbosity good'); # Verbosity: 'label' @@ -55,7 +55,7 @@ $output = qx{../src/task rc:verbose.rc ls rc.verbose:affected}; like ($output, qr/^\d+ tasks$/ms, '\'affected\' verbosity good'); # Off -$output = qx{../src/task rc:verbose.rc ls rc.verbose:off}; +$output = qx{../src/task rc:verbose.rc ls rc.verbose:nothing}; unlike ($output, qr/^\d+ tasks$/ms, '\'affected\' verbosity good'); unlike ($output, qr/ID.+Project.+Pri.+Description/, '\'label\' verbosity good');