diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 08e0968a7..ebd76e594 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -17,6 +17,7 @@ set (columns_SRCS Column.cpp Column.h ColRecur.cpp ColRecur.h ColStart.cpp ColStart.h ColStatus.cpp ColStatus.h + ColString.cpp ColString.h ColTags.cpp ColTags.h ColUntil.cpp ColUntil.h ColUrgency.cpp ColUrgency.h diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp index e441efe9e..5e9e0c2a1 100644 --- a/src/columns/ColRecur.cpp +++ b/src/columns/ColRecur.cpp @@ -89,7 +89,7 @@ void ColumnRecur::render ( if (task.has ("recur")) lines.push_back ( color.colorize ( - rightJustify (context.config.get ("recurrence.indicator").length (), width))); + rightJustify (context.config.get ("recurrence.indicator"), width))); } } diff --git a/src/columns/ColString.cpp b/src/columns/ColString.cpp new file mode 100644 index 000000000..57ea9f28f --- /dev/null +++ b/src/columns/ColString.cpp @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +ColumnString::ColumnString () +{ + _type = "string"; + _style = "default"; + _label = ""; +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnString::~ColumnString () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// ColumnString is unique - it copies the report name into the label. This is +// a kludgy reuse of an otherwise unused member. +void ColumnString::setReport (const std::string& value) +{ + _report = _label = value; +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnString::measure (const std::string& value, int& minimum, int& maximum) +{ + maximum = value.length (); + + if (_style == "fixed") + { + minimum = maximum; + } + else if (_style == "default") + { + minimum = longestWord (value); + } + else + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; + +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnString::render ( + std::vector & lines, + const std::string& value, + int width, + Color& color) +{ + if (_style == "fixed") + { + lines.push_back (value); + } + else if (_style == "default") + { + std::vector raw; + wrapText (raw, value, width); + + std::vector ::iterator i; + for (i = raw.begin (); i != raw.end (); ++i) + lines.push_back (color.colorize (leftJustify (*i, width))); + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColString.h b/src/columns/ColString.h new file mode 100644 index 000000000..14ce9d710 --- /dev/null +++ b/src/columns/ColString.h @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_COLSTRING +#define INCLUDED_COLSTRING + +#include +#include +#include +#include +#include + +class ColumnString : public Column +{ +public: + ColumnString (); + ~ColumnString (); + + void setReport (const std::string&); + void measure (const std::string&, int&, int&); + void render (std::vector &, const std::string&, int, Color&); + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index 666174cbc..5a11c7c69 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -86,8 +87,11 @@ Column* Column::factory (const std::string& name, const std::string& report) else if (column_name == "urgency") column = new ColumnUrgency (); else if (column_name == "uuid") column = new ColumnUUID (); else if (column_name == "wait") column = new ColumnWait (); + + // Special non-task column + else if (column_name == "string") column = new ColumnString (); else - throw std::string ("Unrecognized column name '") + column_name + "'"; + throw std::string ("Unrecognized column name '") + column_name + "'."; column->setReport (report); column->setStyle (column_style); @@ -165,3 +169,27 @@ void Column::renderHeader ( } //////////////////////////////////////////////////////////////////////////////// +void Column::measure (const std::string& value, int& minimum, int& maximum) +{ + throw std::string ("Virtual method Column::measure not overriden."); +} + +//////////////////////////////////////////////////////////////////////////////// +void Column::measure (Task& task, int& minimum, int& maximum) +{ + throw std::string ("Virtual method Column::measure not overriden."); +} + +//////////////////////////////////////////////////////////////////////////////// +void Column::render (std::vector & lines, const std::string& value, int width, Color& color) +{ + throw std::string ("Virtual method Column::render not overriden."); +} + +//////////////////////////////////////////////////////////////////////////////// +void Column::render (std::vector & lines, Task& task, int width, Color& color) +{ + throw std::string ("Virtual method Column::render not overriden."); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.h b/src/columns/Column.h index 75853a4db..8eea53808 100644 --- a/src/columns/Column.h +++ b/src/columns/Column.h @@ -51,9 +51,11 @@ public: virtual void setLabel (const std::string& value) { _label = value; } virtual void setReport (const std::string& value) { _report = value; } - virtual void measure (Task&, int&, int&) = 0; + virtual void measure (const std::string&, int&, int&); + virtual void measure (Task&, int&, int&); virtual void renderHeader (std::vector &, int, Color&); - virtual void render (std::vector &, Task&, int, Color&) = 0; + virtual void render (std::vector &, const std::string&, int, Color&); + virtual void render (std::vector &, Task&, int, Color&); protected: std::string _type;