From ed7fc4468519e64f9decf22dba3e3ca2a779adbc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 29 Apr 2011 23:23:13 -0400 Subject: [PATCH] View - Implemented uuid.default and uuid.short. --- src/columns/CMakeLists.txt | 3 +- src/columns/ColUUID.cpp | 74 ++++++++++++++++++++++++++++++++++++++ src/columns/ColUUID.h | 49 +++++++++++++++++++++++++ src/columns/Column.cpp | 2 ++ test/view.t.cpp | 11 +++--- 5 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/columns/ColUUID.cpp create mode 100644 src/columns/ColUUID.h diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 42b467c0f..9de62d8a2 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -7,7 +7,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src set (columns_SRCS Column.cpp Column.h ColID.cpp ColID.h ColPriority.cpp ColPriority.h - ColProject.cpp ColProject.h) + ColProject.cpp ColProject.h + ColUUID.cpp ColUUID.h) add_library (columns STATIC ${columns_SRCS}) diff --git a/src/columns/ColUUID.cpp b/src/columns/ColUUID.cpp new file mode 100644 index 000000000..5ded9e817 --- /dev/null +++ b/src/columns/ColUUID.cpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +ColumnUUID::ColumnUUID () +{ + _type = "string"; + _style = "default"; + _label = "UUID"; +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnUUID::~ColumnUUID () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnUUID::measure (Task& task, int& minimum, int& maximum) +{ + if (_style == "default") minimum = maximum = 36; + else if (_style == "short") minimum = maximum = 8; + else + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnUUID::render ( + std::vector & lines, + Task& task, + int width, + Color& color) +{ + // f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default + // 34f00694 short + if (_style == "default") + lines.push_back (color.colorize (leftJustify (task.get ("uuid"), width))); + + else if (_style == "short") + lines.push_back (color.colorize (leftJustify (task.get ("uuid").substr (28), width))); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColUUID.h b/src/columns/ColUUID.h new file mode 100644 index 000000000..c272a6955 --- /dev/null +++ b/src/columns/ColUUID.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_COLUUID +#define INCLUDED_COLUUID + +#include +#include +#include +#include +#include + +class ColumnUUID : public Column +{ +public: + ColumnUUID (); + ~ColumnUUID (); + + void measure (Task&, int&, int&); + void render (std::vector &, Task&, int, Color&); + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index 84a37b940..fcff01070 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include extern Context context; @@ -60,6 +61,7 @@ Column* Column::factory (const std::string& name) 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 == "uuid") column = new ColumnUUID (); else throw std::string ("Unrecognized column type '") + column_name + "'"; diff --git a/test/view.t.cpp b/test/view.t.cpp index a8ddf4ef7..611e32412 100644 --- a/test/view.t.cpp +++ b/test/view.t.cpp @@ -44,9 +44,9 @@ int main (int argc, char** argv) context.config.set ("fontunderline", true); // Two sample tasks. - Task t1 ("[project:\"Home\" priority:\"H\"]"); + Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" project:\"Home\" priority:\"H\"]"); t1.id = 1; - Task t2 ("[project:\"Garden Care\"]"); + Task t2 ("[uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" project:\"Garden Care\"]"); t2.id = 11; std::vector data; @@ -64,9 +64,10 @@ int main (int argc, char** argv) // Create a view. View view; view.add (Column::factory ("id")); + view.add (Column::factory ("uuid.short")); view.add (Column::factory ("project")); - view.add (Column::factory ("priority")); - view.width (20); + view.add (Column::factory ("priority.long")); + view.width (80); view.leftMargin (4); view.extraPadding (0); view.intraPadding (1); @@ -75,7 +76,7 @@ int main (int argc, char** argv) // Render the view. std::cout << view.render (data, sequence); - t.is (view.lines (), 4, "View::lines == 4"); + t.is (view.lines (), 3, "View::lines == 3"); } catch (std::string& e)