From 7a8e292fe89e81999a04f396485001722ec8ae0e Mon Sep 17 00:00:00 2001 From: Louis-Claude Canon Date: Sun, 27 May 2012 13:39:47 +0200 Subject: [PATCH] Bug #990 - Precise in the documentation that the wildcards for color precedence must terminate with a dot. If not, 'tag' is completed as 'tagged', which violates the default precedence rule. - Change default precedence rule to reflect this. - Unit test. - ChangeLog and AUTHORS file updated. --- AUTHORS | 1 + ChangeLog | 2 ++ doc/man/task-color.5.in | 4 +-- src/Config.cpp | 2 +- src/rules.cpp | 38 ++++++++++++------------- test/bug.990.t | 61 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 22 deletions(-) create mode 100755 test/bug.990.t diff --git a/AUTHORS b/AUTHORS index 7bd2aaf98..508681491 100644 --- a/AUTHORS +++ b/AUTHORS @@ -138,4 +138,5 @@ suggestions: Andy Spiegl Ethan Schoonover Paul Kishimoto + Jeff Schroeder diff --git a/ChangeLog b/ChangeLog index b350f1a05..3344d571d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -69,6 +69,8 @@ Bugs + Fixed incorrect Lua API return value (thanks to Oleksii Tsai). + Fixed bug #956, which prevents 'ids', 'uuids' and helper commands to be used directly by external script when a variable is override. + + Fixed bug #990, which prevents color precedence to be applied correctly for + tagged tasks. ------ old releases ------------------------------ diff --git a/doc/man/task-color.5.in b/doc/man/task-color.5.in index 30fa34fd5..59738d664 100644 --- a/doc/man/task-color.5.in +++ b/doc/man/task-color.5.in @@ -243,12 +243,12 @@ be a visual mess. Beware! The precedence for the color rules is determined by the configuration variable 'rule.precedence.color', which by default contains: - due.today,active,blocked,overdue,due,keyword,project,tag,recurring,pri,tagged,completed,deleted + due.today,active,blocked,overdue,due,keyword.,project.,tag.,recurring,pri.,tagged,completed,deleted These are just the color rules with the 'color.' prefix removed. The rule 'color.due.today' is the highest precedence, and 'color.deleted' is the lowest. -The keyword rule shown here as 'keyword' corresponds to a wildcard pattern, +The keyword rule shown here as 'keyword.' corresponds to a wildcard pattern, meaning 'color.keyword.*', or in other words all the keyword rules. Similarly for the 'color.tag.*' and 'color.project.*' rules. diff --git a/src/Config.cpp b/src/Config.cpp index 999874838..8705c83ff 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -265,7 +265,7 @@ std::string Config::_defaults = "# Here is the rule precedence order, highest to lowest.\n" "# Note that these are just the color rule names, without the leading 'color.'\n" "# and any trailing '.value'.\n" - "rule.precedence.color=due.today,active,blocked,overdue,due,scheduled,keyword,project,tag,recurring,pri,tagged,completed,deleted\n" + "rule.precedence.color=due.today,active,blocked,overdue,due,scheduled,keyword.,project.,tag.,recurring,pri.,tagged,completed,deleted\n" "\n" "# Shadow file support\n" "#shadow.file=/tmp/shadow.txt # Location of shadow file\n" diff --git a/src/rules.cpp b/src/rules.cpp index 0bff3450f..4fbb7e75d 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -314,27 +314,27 @@ void autoColorize (Task& task, Color& c) std::vector ::reverse_iterator r; for (r = gsPrecedence.rbegin (); r != gsPrecedence.rend (); ++r) { - if (*r == "color.blocked") colorizeBlocked (task, *r, c); - else if (*r == "color.tagged") colorizeTagged (task, *r, c); - else if (*r == "color.pri.L") colorizePriorityL (task, *r, c); - else if (*r == "color.pri.M") colorizePriorityM (task, *r, c); - else if (*r == "color.pri.H") colorizePriorityH (task, *r, c); - else if (*r == "color.pri.none") colorizePriorityNone (task, *r, c); - else if (*r == "color.active") colorizeActive (task, *r, c); - else if (*r == "color.scheduled") colorizeScheduled (task, *r, c); - else if (*r == "color.project.none") colorizeProjectNone (task, *r, c); - else if (*r == "color.tag.none") colorizeTagNone (task, *r, c); - else if (*r == "color.due") colorizeDue (task, *r, c); - else if (*r == "color.due.today") colorizeDueToday (task, *r, c); - else if (*r == "color.overdue") colorizeOverdue (task, *r, c); - else if (*r == "color.recurring") colorizeRecurring (task, *r, c); - else if (*r == "color.completed") colorizeCompleted (task, *r, c); - else if (*r == "color.deleted") colorizeDeleted (task, *r, c); + if (*r == "color.blocked") colorizeBlocked (task, *r, c); + else if (*r == "color.tagged") colorizeTagged (task, *r, c); + else if (*r == "color.pri.L") colorizePriorityL (task, *r, c); + else if (*r == "color.pri.M") colorizePriorityM (task, *r, c); + else if (*r == "color.pri.H") colorizePriorityH (task, *r, c); + else if (*r == "color.pri.none") colorizePriorityNone (task, *r, c); + else if (*r == "color.active") colorizeActive (task, *r, c); + else if (*r == "color.scheduled") colorizeScheduled (task, *r, c); + else if (*r == "color.project.none") colorizeProjectNone (task, *r, c); + else if (*r == "color.tag.none") colorizeTagNone (task, *r, c); + else if (*r == "color.due") colorizeDue (task, *r, c); + else if (*r == "color.due.today") colorizeDueToday (task, *r, c); + else if (*r == "color.overdue") colorizeOverdue (task, *r, c); + else if (*r == "color.recurring") colorizeRecurring (task, *r, c); + else if (*r == "color.completed") colorizeCompleted (task, *r, c); + else if (*r == "color.deleted") colorizeDeleted (task, *r, c); // Wildcards - else if (r->substr (0, 9) == "color.tag") colorizeTag (task, *r, c); - else if (r->substr (0, 13) == "color.project") colorizeProject (task, *r, c); - else if (r->substr (0, 13) == "color.keyword") colorizeKeyword (task, *r, c); + else if (r->substr (0, 10) == "color.tag.") colorizeTag (task, *r, c); + else if (r->substr (0, 14) == "color.project.") colorizeProject (task, *r, c); + else if (r->substr (0, 14) == "color.keyword.") colorizeKeyword (task, *r, c); } } diff --git a/test/bug.990.t b/test/bug.990.t new file mode 100755 index 000000000..2cf8aa0d9 --- /dev/null +++ b/test/bug.990.t @@ -0,0 +1,61 @@ +#! /usr/bin/perl +################################################################################ +## taskwarrior - a command line task list manager. +## +## Copyright 2006-2012, Paul Beckingham, Federico Hernandez. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in the Software without restriction, including without limitation the rights +## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +## copies of the Software, and to permit persons to whom the Software is +## furnished to do so, subject to the following conditions: +## +## The above copyright notice and this permission notice shall be included +## in all copies or substantial portions of the Software. +## +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +## SOFTWARE. +## +## http://www.opensource.org/licenses/mit-license.php +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 3; + +# Create the rc file. +if (open my $fh, '>', 'color.rc') +{ + print $fh "data.location=.\n", + "color.pri.L=green\n", + "color.tagged=red\n", + "_forcecolor=1\n"; + close $fh; + ok (-r 'color.rc', 'Created color.rc'); +} + +# Bug that colored any task with both priority:L and a tag as though +# rc.color.tagged had a higher precedence than rc.color.pri.L, which it is not. + +qx{../src/task rc:color.rc add test +test pri:L}; +my $output = qx{../src/task rc:color.rc list}; +like ($output, qr/ \033\[32m .* test .* \033\[0m /x, 'Colored with the priority color, which has precedence over the tagged color'); + +# Cleanup. +unlink qw(pending.data completed.data undo.data backlog.data synch.key color.rc); +ok (! -r 'pending.data' && + ! -r 'completed.data' && + ! -r 'undo.data' && + ! -r 'backlog.data' && + ! -r 'synch.key' && + ! -r 'color.rc', 'Cleanup'); + +exit 0; +