- Implemented (a fraction of) description columns.
This commit is contained in:
Paul Beckingham 2011-04-30 18:03:18 -04:00
parent 6974e48290
commit ac69c02876
7 changed files with 262 additions and 13 deletions

View file

@ -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

View file

@ -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 <Context.h>
#include <Nibbler.h>
#include <ColDescription.h>
#include <text.h>
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 <Att> annos;
task.getAnnotations (annos);
*/
// TODO Render Date () in appropriate format, to calculate length.
// The text
// <date> <anno>
// ...
if (_style == "default")
{
}
// The text
else if (_style == "desc")
{
}
// The text <date> <anno> ...
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 <std::string>& lines,
Task& task,
int width,
Color& color)
{
std::string description = task.get ("description");
// This is a description
// <date> <anno>
// ...
if (_style == "default")
{
}
// This is a description
else if (_style == "desc")
{
std::vector <std::string> raw;
wrapText (raw, description, width);
std::vector <std::string>::iterator i;
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
}
// This is a description <date> <anno> ...
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")
{
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnDescription : public Column
{
public:
ColumnDescription ();
~ColumnDescription ();
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -117,7 +117,7 @@ void ColumnTags::render (
std::vector <std::string>::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)));
}
}
}

View file

@ -27,11 +27,20 @@
#include <Context.h>
#include <Column.h>
//#include <ColDepends.h>
#include <ColDescription.h>
//#include <ColDue.h>
//#include <ColEnd.h>
//#include <ColEntry.h>
#include <ColID.h>
#include <ColPriority.h>
#include <ColProject.h>
//#include <ColRecur.h>
//#include <ColStart.h>
#include <ColTags.h>
//#include <ColUntilDepends.h>
#include <ColUUID.h>
//#include <ColWait.h>
#include <text.h>
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 + "'";

View file

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

View file

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