- Implemented due.countdown.
- Fixed formatting bug in description.truncated.
- Fixed bug in start.indicator.
This commit is contained in:
Paul Beckingham 2011-05-02 23:43:41 -04:00
parent f9ab8f2a1c
commit d0cbf43478
6 changed files with 69 additions and 13 deletions

View file

@ -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 + "'";
}

View file

@ -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)));
}

View file

@ -25,7 +25,14 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <Context.h>
#include <ColDue.h>
#include <Date.h>
#include <Duration.h>
#include <text.h>
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 <std::string>& 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);
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 <std::string>&, Task&, int, Color&);
};
#endif

View file

@ -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);
}

View file

@ -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"));