From e1407437e04b8804fcc180b69bd909fd1b993405 Mon Sep 17 00:00:00 2001 From: Louis-Claude Canon Date: Tue, 26 Jun 2012 09:30:39 +0200 Subject: [PATCH] Enhancement - Allow a separate color for error messages via the 'color.error' configuration variable. --- ChangeLog | 1 + doc/man/task-tutorial.5.in | 2 + doc/man/taskrc.5.in | 5 +++ doc/rc/dark-16.theme | 1 + doc/rc/dark-256.theme | 1 + doc/rc/dark-blue-256.theme | 1 + doc/rc/dark-gray-256.theme | 1 + doc/rc/dark-green-256.theme | 1 + doc/rc/dark-red-256.theme | 1 + doc/rc/dark-violets-256.theme | 1 + doc/rc/dark-yellow-green.theme | 1 + doc/rc/light-16.theme | 1 + doc/rc/light-256.theme | 1 + doc/rc/solarized-dark-256.theme | 1 + doc/rc/solarized-light-256.theme | 1 + src/Config.cpp | 2 + src/Context.cpp | 2 +- src/commands/CmdShow.cpp | 1 + src/main.h | 1 + src/rules.cpp | 9 +++++ test/color.err.t | 63 ++++++++++++++++++++++++++++++++ 21 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 test/color.err.t diff --git a/ChangeLog b/ChangeLog index e343973e3..69a8f8371 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ Features with 'dateformat.info'. + Bash script improvement (column names are now completed). + Feature #1013, output error, header, footnote and debug messages on standard error. + + Color error messages with a specific configuration variable 'color.error'. Bugs + Applied patch for bug #919, so the holidays listed on the 'calendar' report diff --git a/doc/man/task-tutorial.5.in b/doc/man/task-tutorial.5.in index dcfc6fe2d..4fb084834 100644 --- a/doc/man/task-tutorial.5.in +++ b/doc/man/task-tutorial.5.in @@ -1283,6 +1283,8 @@ color.due red .br color.due.today red .br +color.error yellow +.br color.footnote yellow .br color.header yellow diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index de80c6817..89806b970 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -812,6 +812,11 @@ Colors any task assigned to project X. Colors any task where the description or any annotation contains X. .RE +.TP +.B color.error=green +Colors any of the error messages. +.RE + .TP .B color.header=green Colors any of the messages printed prior to the report output. diff --git a/doc/rc/dark-16.theme b/doc/rc/dark-16.theme index fe30bea24..d79b6fd36 100644 --- a/doc/rc/dark-16.theme +++ b/doc/rc/dark-16.theme @@ -30,6 +30,7 @@ color=on color.header=yellow color.footnote=yellow +color.error=yellow color.debug=yellow color.summary.bar=black on green diff --git a/doc/rc/dark-256.theme b/doc/rc/dark-256.theme index fdb16fb5f..9bf5fb495 100644 --- a/doc/rc/dark-256.theme +++ b/doc/rc/dark-256.theme @@ -30,6 +30,7 @@ color=on color.header=color3 color.footnote=color3 +color.error=color3 color.debug=color3 color.summary.bar=black on rgb141 diff --git a/doc/rc/dark-blue-256.theme b/doc/rc/dark-blue-256.theme index 4fe66a39b..cb5ca66e9 100644 --- a/doc/rc/dark-blue-256.theme +++ b/doc/rc/dark-blue-256.theme @@ -30,6 +30,7 @@ color=on color.header=rgb013 color.footnote=rgb013 +color.error=rgb013 color.debug=rgb013 color.summary.bar=white on rgb003 diff --git a/doc/rc/dark-gray-256.theme b/doc/rc/dark-gray-256.theme index 620955144..b2c67e078 100644 --- a/doc/rc/dark-gray-256.theme +++ b/doc/rc/dark-gray-256.theme @@ -30,6 +30,7 @@ color=on color.header=color8 color.footnote=color8 +color.error=color8 color.debug=color8 color.summary.bar=black on gray12 diff --git a/doc/rc/dark-green-256.theme b/doc/rc/dark-green-256.theme index 464c9c800..43b0d8afe 100644 --- a/doc/rc/dark-green-256.theme +++ b/doc/rc/dark-green-256.theme @@ -30,6 +30,7 @@ color=on color.header=rgb031 color.footnote=rgb031 +color.error=rgb031 color.debug=rgb031 color.summary.bar=white on rgb030 diff --git a/doc/rc/dark-red-256.theme b/doc/rc/dark-red-256.theme index de0491bba..7510a45ff 100644 --- a/doc/rc/dark-red-256.theme +++ b/doc/rc/dark-red-256.theme @@ -30,6 +30,7 @@ color=on color.header=rgb100 color.footnote=rgb100 +color.error=rgb100 color.debug=rgb100 color.summary.bar=white on rgb300 diff --git a/doc/rc/dark-violets-256.theme b/doc/rc/dark-violets-256.theme index 99978dc7c..41460ca5a 100644 --- a/doc/rc/dark-violets-256.theme +++ b/doc/rc/dark-violets-256.theme @@ -30,6 +30,7 @@ color=on color.header=rgb013 color.footnote=rgb013 +color.error=rgb013 color.debug=rgb013 color.summary.bar=white on rgb103 diff --git a/doc/rc/dark-yellow-green.theme b/doc/rc/dark-yellow-green.theme index ca01466d7..f3300e451 100644 --- a/doc/rc/dark-yellow-green.theme +++ b/doc/rc/dark-yellow-green.theme @@ -30,6 +30,7 @@ color=on color.header=rgb031 color.footnote=rgb031 +color.error=rgb031 color.debug=rgb031 color.summary.bar=white on rgb030 diff --git a/doc/rc/light-16.theme b/doc/rc/light-16.theme index 765906b66..ede5a7178 100644 --- a/doc/rc/light-16.theme +++ b/doc/rc/light-16.theme @@ -30,6 +30,7 @@ color=on color.header=blue color.footnote=blue +color.error=blue color.debug=blue color.summary.bar=black on green diff --git a/doc/rc/light-256.theme b/doc/rc/light-256.theme index 286e0124d..bf2553581 100644 --- a/doc/rc/light-256.theme +++ b/doc/rc/light-256.theme @@ -30,6 +30,7 @@ color=on color.header=color4 color.footnote=color4 +color.error=color4 color.debug=color4 color.summary.bar=black on rgb141 diff --git a/doc/rc/solarized-dark-256.theme b/doc/rc/solarized-dark-256.theme index 41ea5f396..7f66c69c8 100644 --- a/doc/rc/solarized-dark-256.theme +++ b/doc/rc/solarized-dark-256.theme @@ -60,6 +60,7 @@ color.calendar.today=color0 on color4 color.calendar.weekend=on color0 color.calendar.weeknumber=color4 +color.error=color6 color.debug=color6 color.due=color9 color.due.today=color1 diff --git a/doc/rc/solarized-light-256.theme b/doc/rc/solarized-light-256.theme index 3677e98ad..9eb855a45 100644 --- a/doc/rc/solarized-light-256.theme +++ b/doc/rc/solarized-light-256.theme @@ -60,6 +60,7 @@ color.calendar.today=color7 on color4 color.calendar.weekend=on color7 color.calendar.weeknumber=color14 +color.error=color2 color.debug=color3 color.due=color9 color.due.today=color1 diff --git a/src/Config.cpp b/src/Config.cpp index 8705c83ff..a4450364b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -159,6 +159,7 @@ std::string Config::_defaults = #ifdef LINUX "color.header=color3 # Color of header messages\n" "color.footnote=color3 # Color of footnote messages\n" + "color.error=color3 # Color of error messages\n" "color.debug=color3 # Color of diagnostic output\n" "color.alternate=on color233 # Alternate color for line coloring\n" "\n" @@ -211,6 +212,7 @@ std::string Config::_defaults = #else "color.header=yellow # Color of header messages\n" "color.footnote=yellow # Color of footnote messages\n" + "color.error=yellow # Color of error messages\n" "color.debug=yellow # Color of diagnostic output\n" "color.alternate= # Alternate color for line coloring\n" "\n" diff --git a/src/Context.cpp b/src/Context.cpp index 921416ec4..d5c9c1317 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -345,7 +345,7 @@ int Context::run () std::vector ::iterator e; for (e = errors.begin (); e != errors.end (); ++e) if (color ()) - std::cerr << colorizeFootnote (*e) << "\n"; + std::cerr << colorizeError (*e) << "\n"; else std::cerr << *e << "\n"; diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index 107676b51..5d60065cb 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -100,6 +100,7 @@ int CmdShow::execute (std::string& output) " color.deleted" " color.due" " color.due.today" + " color.error" " color.footnote" " color.header" " color.history.add" diff --git a/src/main.h b/src/main.h index 5da13375b..6d35fa26e 100644 --- a/src/main.h +++ b/src/main.h @@ -55,6 +55,7 @@ void initializeColorRules (); void autoColorize (Task&, Color&); std::string colorizeHeader (const std::string&); std::string colorizeFootnote (const std::string&); +std::string colorizeError (const std::string&); std::string colorizeDebug (const std::string&); // dependency.cpp diff --git a/src/rules.cpp b/src/rules.cpp index 4fbb7e75d..b77916912 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -356,6 +356,15 @@ std::string colorizeFootnote (const std::string& input) return input; } +//////////////////////////////////////////////////////////////////////////////// +std::string colorizeError (const std::string& input) +{ + if (gsColor["color.error"].nontrivial ()) + return gsColor["color.error"].colorize (input); + + return input; +} + //////////////////////////////////////////////////////////////////////////////// std::string colorizeDebug (const std::string& input) { diff --git a/test/color.err.t b/test/color.err.t new file mode 100755 index 000000000..2de132ee3 --- /dev/null +++ b/test/color.err.t @@ -0,0 +1,63 @@ +#! /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 => 6; + +# Create the rc file. +if (open my $fh, '>', 'color.rc') +{ + print $fh "data.location=.\n", + "color.header=blue\n", + "color.footnote=red\n", + "color.error=yellow\n", + "color.debug=green\n", + "_forcecolor=1\n"; + close $fh; + ok (-r 'color.rc', 'Created color.rc'); +} + +# Test the errors colors +my $output = qx{../src/task rc:color.rc rc.debug:on add due:__ 2>&1 >/dev/null}; +like ($output, qr/^\033\[33mThe\ date\/duration\ '__'\ was\ not\ recognized.\033\[0m$/xms, 'color.error'); +like ($output, qr/^\033\[32mTimer\ Config::load\ \(color.rc\) .* \033\[0m$/xms, 'color.debug'); +like ($output, qr/^\033\[34mUsing\ alternate\ .taskrc\ file\ color.rc\033\[0m$/xms, 'color.header'); +like ($output, qr/^\033\[31mConfiguration\ override\ rc.debug:on\033\[0m$/xms, 'color.footnote'); + +# 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; +