From ac69c028763c56b47831a5d5a55975d7d2336500 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 30 Apr 2011 18:03:18 -0400 Subject: [PATCH] View - Implemented (a fraction of) description columns. --- src/columns/CMakeLists.txt | 1 + src/columns/ColDescription.cpp | 167 +++++++++++++++++++++++++++++++++ src/columns/ColDescription.h | 49 ++++++++++ src/columns/ColTags.cpp | 2 +- src/columns/Column.cpp | 28 +++++- src/report.cpp | 8 +- test/view.t.cpp | 20 +++- 7 files changed, 262 insertions(+), 13 deletions(-) create mode 100644 src/columns/ColDescription.cpp create mode 100644 src/columns/ColDescription.h diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 5d8e07b79..a175cca6d 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories (${CMAKE_SOURCE_DIR}/src ${TASK_INCLUDE_DIRS}) set (columns_SRCS Column.cpp Column.h + ColDescription.cpp ColDescription.h ColID.cpp ColID.h ColPriority.cpp ColPriority.h ColProject.cpp ColProject.h diff --git a/src/columns/ColDescription.cpp b/src/columns/ColDescription.cpp new file mode 100644 index 000000000..1c506d67e --- /dev/null +++ b/src/columns/ColDescription.cpp @@ -0,0 +1,167 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +ColumnDescription::ColumnDescription () +{ + _type = "string"; + _style = "default"; + _label = "Description"; +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnDescription::~ColumnDescription () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnDescription::measure (Task& task, int& minimum, int& maximum) +{ + std::string description = task.get ("description"); + +/* + std::vector annos; + task.getAnnotations (annos); +*/ + + // TODO Render Date () in appropriate format, to calculate length. + + // The text + // + // ... + if (_style == "default") + { + } + + // The text + else if (_style == "desc") + { + } + + // The text ... + else if (_style == "oneline") + { + } + + // The te... + else if (_style == "truncated") + { + minimum = 4; + maximum = description.length (); + } + + // The text [2] + else if (_style == "count") + { + } + + else + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; + +/* + std::string project = task.get ("project"); + + if (_style == "parent") + { + std::string::size_type period = project.find ('.'); + if (period != std::string::npos) + project = project.substr (0, period); + } + else if (_style != "default") + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; + + minimum = 0; + maximum = project.length (); + + Nibbler nibbler (project); + std::string word; + while (nibbler.getUntilWS (word)) + { + nibbler.skipWS (); + if (word.length () > minimum) + minimum = word.length (); + } +*/ +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnDescription::render ( + std::vector & lines, + Task& task, + int width, + Color& color) +{ + std::string description = task.get ("description"); + + // This is a description + // + // ... + if (_style == "default") + { + } + + // This is a description + else if (_style == "desc") + { + std::vector raw; + wrapText (raw, description, width); + + std::vector ::iterator i; + for (i = raw.begin (); i != raw.end (); ++i) + lines.push_back (color.colorize (leftJustify (*i, width))); + } + + // This is a description ... + else if (_style == "oneline") + { + } + + // This is a des... + else if (_style == "truncated") + { + int len = description.length (); + if (len > width) + lines.push_back (color.colorize (description.substr (0, len - 3) + "...")); + else + lines.push_back (color.colorize (leftJustify (description, width))); + } + + // This is a description [2] + else if (_style == "count") + { + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColDescription.h b/src/columns/ColDescription.h new file mode 100644 index 000000000..d51aa8b3e --- /dev/null +++ b/src/columns/ColDescription.h @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_COLDESCRIPTION +#define INCLUDED_COLDESCRIPTION + +#include +#include +#include +#include +#include + +class ColumnDescription : public Column +{ +public: + ColumnDescription (); + ~ColumnDescription (); + + void measure (Task&, int&, int&); + void render (std::vector &, Task&, int, Color&); + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColTags.cpp b/src/columns/ColTags.cpp index 30a48edc7..56e1face0 100644 --- a/src/columns/ColTags.cpp +++ b/src/columns/ColTags.cpp @@ -117,7 +117,7 @@ void ColumnTags::render ( std::vector ::iterator i; for (i = all.begin (); i != all.end (); ++i) - lines.push_back (color.colorize (rightJustify (*i, width))); + lines.push_back (color.colorize (leftJustify (*i, width))); } } } diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index b5d9dee9f..172b9b62a 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -27,11 +27,20 @@ #include #include +//#include +#include +//#include +//#include +//#include #include #include #include +//#include +//#include #include +//#include #include +//#include #include extern Context context; @@ -59,11 +68,20 @@ Column* Column::factory (const std::string& name) } Column* column; - if (column_name == "id") column = new ColumnID (); - else if (column_name == "priority") column = new ColumnPriority (); - else if (column_name == "project") column = new ColumnProject (); - else if (column_name == "tags") column = new ColumnTags (); - else if (column_name == "uuid") column = new ColumnUUID (); +// if (column_name == "depends") column = new ColumnDepends (); + if (column_name == "description") column = new ColumnDescription (); +// else if (column_name == "due") column = new ColumnDue (); +// else if (column_name == "end") column = new ColumnEnd (); +// else if (column_name == "entry") column = new ColumnEntry (); + else if (column_name == "id") column = new ColumnID (); + else if (column_name == "priority") column = new ColumnPriority (); + else if (column_name == "project") column = new ColumnProject (); +// else if (column_name == "recur") column = new ColumnRecur (); +// else if (column_name == "start") column = new ColumnStart (); + else if (column_name == "tags") column = new ColumnTags (); +// else if (column_name == "until") column = new ColumnUntil (); + else if (column_name == "uuid") column = new ColumnUUID (); +// else if (column_name == "wait") column = new ColumnWait (); else throw std::string ("Unrecognized column type '") + column_name + "'"; diff --git a/src/report.cpp b/src/report.cpp index eb4012a3b..e6674bd6f 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -229,7 +229,7 @@ int shortUsage (std::string& outs) table.addCell (row, 1, "task push URL"); table.addCell (row, 2, "Pushes the local *.data files to the URL."); - row = table.addRow (); + row = table.addRow (); table.addCell (row, 1, "task pull URL"); table.addCell (row, 2, "Overwrites the local *.data files with those found at the URL."); @@ -2146,9 +2146,9 @@ std::string getFullDescription (Task& task, const std::string& report) foreach (anno, annotations) { Date dt (atoi (anno->name ().substr (11).c_str ())); - std::string format = context.config.get ("dateformat.annotation"); - if (format == "") - format = context.config.get ("dateformat"); + std::string format = context.config.get ("dateformat.annotation"); + if (format == "") + format = context.config.get ("dateformat"); std::string when = dt.toString (format); desc += "\n" + when + " " + anno->value (); } diff --git a/test/view.t.cpp b/test/view.t.cpp index 1ba6c44a0..eed333c22 100644 --- a/test/view.t.cpp +++ b/test/view.t.cpp @@ -45,9 +45,9 @@ int main (int argc, char** argv) context.config.set ("tag.indicator", "+"); // Two sample tasks. - Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" project:\"Home\" priority:\"H\" tags:\"one,two\"]"); + Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" description:\"This is the description text\" project:\"Home\" priority:\"H\" tags:\"one,two\"]"); t1.id = 1; - Task t2 ("[uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" project:\"Garden Care\"]"); + Task t2 ("[uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" description:\"This is the description text\" project:\"Garden Care\"]"); t2.id = 11; std::vector data; @@ -61,6 +61,8 @@ int main (int argc, char** argv) // Create colors. Color header_color (Color (Color::yellow, Color::nocolor, false, false, false)); + Color odd_color ("on gray1"); + Color even_color ("on gray0"); // Create a view. View view; @@ -71,11 +73,23 @@ int main (int argc, char** argv) view.add (Column::factory ("tags")); view.add (Column::factory ("tags.indicator")); view.add (Column::factory ("tags.count")); - view.width (80); + view.add (Column::factory ("description.truncated")); + view.width (64); view.leftMargin (4); +/* + view.extraPadding (1); +*/ view.extraPadding (0); view.intraPadding (1); view.colorHeader (header_color); + view.colorOdd (odd_color); + view.colorEven (even_color); + view.intraColorOdd (odd_color); + view.intraColorEven (even_color); +/* + view.extraColorOdd (odd_color); + view.extraColorEven (even_color); +*/ // Render the view. std::cout << view.render (data, sequence);