diff --git a/src/columns/ColDate.cpp b/src/columns/ColDate.cpp index bb80efafb..f271887c8 100644 --- a/src/columns/ColDate.cpp +++ b/src/columns/ColDate.cpp @@ -99,15 +99,6 @@ void ColumnDate::measure (Task& task, int& minimum, int& maximum) Date now; minimum = maximum = Duration (now - date).format ().length (); } - else if (_style == "short") - { - } - else if (_style == "countdown") - { - } - else if (_style == "remaining") - { - } else throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; } diff --git a/src/columns/ColDescription.cpp b/src/columns/ColDescription.cpp index 1c506d67e..d3d3c526d 100644 --- a/src/columns/ColDescription.cpp +++ b/src/columns/ColDescription.cpp @@ -153,7 +153,7 @@ void ColumnDescription::render ( { int len = description.length (); if (len > width) - lines.push_back (color.colorize (description.substr (0, len - 3) + "...")); + lines.push_back (color.colorize (description.substr (0, width - 3) + "...")); else lines.push_back (color.colorize (leftJustify (description, width))); } diff --git a/src/columns/ColDue.cpp b/src/columns/ColDue.cpp index 685df755e..0512be23e 100644 --- a/src/columns/ColDue.cpp +++ b/src/columns/ColDue.cpp @@ -25,7 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#include +#include #include +#include +#include +#include + +extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnDue::ColumnDue () @@ -40,3 +47,57 @@ ColumnDue::~ColumnDue () } //////////////////////////////////////////////////////////////////////////////// +// Overriden so that style <----> label are linked. +// Note that you can not determine which gets called first. +void ColumnDue::setStyle (const std::string& value) +{ + _style = value; + + if (_style == "countdown" && _label == "Due") + _label = "Countdown"; +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnDue::measure (Task& task, int& minimum, int& maximum) +{ + minimum = maximum = 0; + + if (task.has (_attribute)) + { + if (_style == "countdown") + { + Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date now; + minimum = maximum = Duration (now - date).format ().length (); + } + else + ColumnDate::measure (task, minimum, maximum); + } +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnDue::render ( + std::vector & lines, + Task& task, + int width, + Color& color) +{ + if (task.has (_attribute)) + { + if (_style == "countdown") + { + Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date now; + + lines.push_back ( + color.colorize ( + rightJustify ( + Duration (now - date).format (), width))); + } + else + ColumnDate::render (lines, task, width, color); + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColDue.h b/src/columns/ColDue.h index 279e7d2a7..cf1bad015 100644 --- a/src/columns/ColDue.h +++ b/src/columns/ColDue.h @@ -34,6 +34,10 @@ class ColumnDue : public ColumnDate public: ColumnDue (); ~ColumnDue (); + + void setStyle (const std::string&); + void measure (Task&, int&, int&); + void render (std::vector &, Task&, int, Color&); }; #endif diff --git a/src/columns/ColStart.cpp b/src/columns/ColStart.cpp index f7e0e223d..95f94ab44 100644 --- a/src/columns/ColStart.cpp +++ b/src/columns/ColStart.cpp @@ -63,8 +63,7 @@ void ColumnStart::measure (Task& task, int& minimum, int& maximum) if (task.has (_attribute)) { if (_style == "active") - { - } + minimum = maximum = context.config.get ("active.indicator").length (); else ColumnDate::measure (task, minimum, maximum); } diff --git a/test/view.t.cpp b/test/view.t.cpp index 942a60c92..1ac437d12 100644 --- a/test/view.t.cpp +++ b/test/view.t.cpp @@ -104,7 +104,8 @@ int main (int argc, char** argv) // view.add (Column::factory ("status")); view.add (Column::factory ("status.short")); // view.add (Column::factory ("due")); - view.add (Column::factory ("due.julian")); +// view.add (Column::factory ("due.julian")); + view.add (Column::factory ("due.countdown")); // view.add (Column::factory ("due.epoch")); // view.add (Column::factory ("due.iso")); view.add (Column::factory ("start.active"));