From d7c225c87bae4f7044b19406787e26df6c435a07 Mon Sep 17 00:00:00 2001 From: Scott Kostyshak Date: Sun, 30 Dec 2012 20:09:32 -0500 Subject: [PATCH] Feature - Add the configuration variable 'print.empty.columns'. - If this variable is set to 'no', columns with all empty values are not printed. This variable defaults to 'yes' (thus nothing is changed by default). - Updated taskrc.5.in to mention the new variable. - Added unit tests. --- ChangeLog | 1 + doc/man/taskrc.5.in | 5 +++ src/Config.cpp | 1 + src/ViewTask.cpp | 23 ++++++++++-- src/columns/ColPriority.cpp | 6 ++- test/feature.print.empty.columns.t | 60 ++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100755 test/feature.print.empty.columns.t diff --git a/ChangeLog b/ChangeLog index a4d121bb8..f155d8409 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,7 @@ Features if a modification has occurred. + Fixed the mechanism used for selecting translations (thanks to Fidel Mato). + Added new export script: export-tsv.pl. + + Added the configuration variable 'print.empty.columns'. Bugs + Fixed bug #947, #1031, which kept expanding aliases after the '--' operator diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index ae7935e23..d75f18925 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -346,6 +346,11 @@ May be yes or no, and determines whether the 'tags' command lists all the tag names you have used, or just the ones used in active tasks. The default value is "no". +.TP +.B print.empty.columns=yes +May be yes or no, and determines whether columns with no data for any task are +printed. Defaults to yes. + .TP .B search.case.sensitive=yes May be yes or no, and determines whether keyword lookup and substitutions on the diff --git a/src/Config.cpp b/src/Config.cpp index 9ed9701e1..1f0eda8a1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -289,6 +289,7 @@ std::string Config::_defaults = "complete.all.tags=no # Include old tag names in '_ags' command\n" "list.all.projects=no # Include old project names in 'projects' command\n" "list.all.tags=no # Include old tag names in 'tags' command\n" + "print.empty.columns=yes # Print columns which have no data for any task\n" "debug=no # Display diagnostics\n" "extensions=off # Extension system master switch\n" "fontunderline=yes # Uses underlines rather than -------\n" diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index c65255471..2603ba8d7 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -113,6 +113,9 @@ std::string ViewTask::render (std::vector & data, std::vector & seque { context.timer_render.start (); + bool const print_empty_columns = context.config.getBoolean ("print.empty.columns"); + std::vector nonempty_columns; + // Determine minimal, ideal column widths. std::vector minimal; std::vector ideal; @@ -121,7 +124,7 @@ std::string ViewTask::render (std::vector & data, std::vector & seque for (i = _columns.begin (); i != _columns.end (); ++i) { // Headers factor in to width calculations. - int global_min = utf8_length ((*i)->label ()); + int global_min = 0; int global_ideal = global_min; for (unsigned int s = 0; s < sequence.size (); ++s) @@ -141,10 +144,24 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (ideal > global_ideal) global_ideal = ideal; } - minimal.push_back (global_min); - ideal.push_back (global_ideal); + if (print_empty_columns || global_min != 0) + { + int label_length = utf8_length ((*i)->label ()); + if (label_length > global_min) global_min = label_length; + if (label_length > global_ideal) global_ideal = label_length; + minimal.push_back (global_min); + ideal.push_back (global_ideal); + } + + if (!print_empty_columns && global_min != 0) + { + nonempty_columns.push_back(*i); + } } + if (!print_empty_columns) + _columns = nonempty_columns; + // Sum the minimal widths. int sum_minimal = 0; std::vector ::iterator c; diff --git a/src/columns/ColPriority.cpp b/src/columns/ColPriority.cpp index aa12240e6..8f9cb8472 100644 --- a/src/columns/ColPriority.cpp +++ b/src/columns/ColPriority.cpp @@ -85,7 +85,11 @@ void ColumnPriority::measure (Task& task, int& minimum, int& maximum) { std::string priority = task.get (_name); - minimum = maximum = 1; + if (priority == "") + minimum = maximum = 0; + else + minimum = maximum = 1; + if (_style == "long") { if (priority == "H") minimum = maximum = 4; diff --git a/test/feature.print.empty.columns.t b/test/feature.print.empty.columns.t new file mode 100755 index 000000000..b4fa99827 --- /dev/null +++ b/test/feature.print.empty.columns.t @@ -0,0 +1,60 @@ +#! /usr/bin/env 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 => 4; + +# Create the rc file. +if (open my $fh, '>', 'bug.rc') +{ + print $fh "data.location=.\n"; + print $fh "report.test.columns=id,project\n"; + close $fh; + ok (-r 'bug.rc', 'Created bug.rc'); +} + +# Feature: variable to control printing of empty columns +qx{../src/task rc:bug.rc add sample desc 2>&1}; + +my $output = qx{../src/task test rc:bug.rc 2>&1}; +like ($output, qr/Project/, 'empty \'project\' column is printed by default'); + +$output = qx{../src/task test rc.print.empty.columns:no rc:bug.rc 2>&1}; +unlike ($output, qr/Project/, 'empty \'project\' column is not printed if rc.print.empty.columns:no'); + +# Cleanup. +unlink qw(pending.data completed.data undo.data backlog.data synch.key bug.rc); +ok (! -r 'pending.data' && + ! -r 'completed.data' && + ! -r 'undo.data' && + ! -r 'backlog.data' && + ! -r 'synch.key' && + ! -r 'bug.rc', 'Cleanup'); + +exit 0;