mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
View
- Implemented 'description.default', 'description.count', and 'description.oneline'. - New 'indent.annotation' for the 'description.default' field format.
This commit is contained in:
parent
f37a250894
commit
28b0960015
8 changed files with 145 additions and 33 deletions
|
@ -73,6 +73,7 @@ std::string Config::defaults =
|
|||
"confirmation=yes # Confirmation on delete, big changes\n"
|
||||
"echo.command=yes # Details on command just run\n"
|
||||
"annotations=full # Level of verbosity for annotations: full, sparse or none\n"
|
||||
"indent.annotation=1 # Indent spaces for annotations\n"
|
||||
"next=2 # How many tasks per project in next report\n"
|
||||
"bulk=2 # > 2 tasks considered 'a lot', for confirmation\n"
|
||||
"nag=You have more urgent tasks. # Nag message to keep you honest\n" // TODO
|
||||
|
|
32
src/Date.cpp
32
src/Date.cpp
|
@ -694,6 +694,38 @@ int Date::monthOfYear (const std::string& input)
|
|||
return -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Date::length (const std::string& format)
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
std::string::const_iterator i;
|
||||
for (i = format.begin (); i != format.end (); ++i)
|
||||
{
|
||||
switch (*i)
|
||||
{
|
||||
case 'm':
|
||||
case 'M':
|
||||
case 'd':
|
||||
case 'D':
|
||||
case 'y':
|
||||
case 'A':
|
||||
case 'b':
|
||||
case 'B':
|
||||
case 'V':
|
||||
case 'h':
|
||||
case 'H':
|
||||
case 'N':
|
||||
case 'S': total += 2; break;
|
||||
case 'a': total += 3; break;
|
||||
case 'Y': total += 4; break;
|
||||
default: total += 1; break;
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Date::easter (int year)
|
||||
{
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
static int weekOfYear (const std::string&);
|
||||
static int dayOfWeek (const std::string&);
|
||||
static int monthOfYear (const std::string&);
|
||||
static int length (const std::string&);
|
||||
|
||||
int month () const;
|
||||
int day () const;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <Context.h>
|
||||
#include <Nibbler.h>
|
||||
#include <Date.h>
|
||||
#include <ColDescription.h>
|
||||
#include <text.h>
|
||||
|
||||
|
@ -51,18 +52,25 @@ 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")
|
||||
{
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
std::string format = context.config.get ("dateformat.annotation");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
minimum = Date::length (format);
|
||||
maximum = description.length ();
|
||||
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
std::vector <Att>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
if (indent + i->value ().length () + minimum + 1 > maximum)
|
||||
maximum = indent + i->value ().length () + minimum + 1;
|
||||
}
|
||||
|
||||
// Just the text
|
||||
|
@ -84,6 +92,18 @@ void ColumnDescription::measure (Task& task, int& minimum, int& maximum)
|
|||
// The text <date> <anno> ...
|
||||
else if (_style == "oneline")
|
||||
{
|
||||
std::string format = context.config.get ("dateformat.annotation");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
minimum = Date::length (format);
|
||||
maximum = description.length ();
|
||||
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
std::vector <Att>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
maximum += i->value ().length () + minimum + 1;
|
||||
}
|
||||
|
||||
// The te...
|
||||
|
@ -96,35 +116,25 @@ void ColumnDescription::measure (Task& task, int& minimum, int& maximum)
|
|||
// The text [2]
|
||||
else if (_style == "count")
|
||||
{
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
|
||||
// <description> + ' ' + '[' + <count> + ']'
|
||||
maximum = description.length () + 3 + format ((int)annos.size ()).length ();
|
||||
minimum = 0;
|
||||
|
||||
Nibbler nibbler (description);
|
||||
std::string word;
|
||||
while (nibbler.getUntilWS (word))
|
||||
{
|
||||
nibbler.skipWS ();
|
||||
if (word.length () > minimum)
|
||||
minimum = word.length ();
|
||||
}
|
||||
}
|
||||
|
||||
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 ();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -141,6 +151,29 @@ void ColumnDescription::render (
|
|||
// ...
|
||||
if (_style == "default")
|
||||
{
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
if (annos.size ())
|
||||
{
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
std::string format = context.config.get ("dateformat.annotation");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
std::vector <Att>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
{
|
||||
Date dt (atoi (i->name ().substr (11).c_str ()));
|
||||
description += "\n" + std::string (indent, ' ') + dt.toString (format) + " " + i->value ();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -157,6 +190,28 @@ void ColumnDescription::render (
|
|||
// This is a description <date> <anno> ...
|
||||
else if (_style == "oneline")
|
||||
{
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
if (annos.size ())
|
||||
{
|
||||
std::string format = context.config.get ("dateformat.annotation");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
||||
std::vector <Att>::iterator i;
|
||||
for (i = annos.begin (); i != annos.end (); i++)
|
||||
{
|
||||
Date dt (atoi (i->name ().substr (11).c_str ()));
|
||||
description += " " + dt.toString (format) + " " + i->value ();
|
||||
}
|
||||
}
|
||||
|
||||
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 des...
|
||||
|
@ -172,6 +227,18 @@ void ColumnDescription::render (
|
|||
// This is a description [2]
|
||||
else if (_style == "count")
|
||||
{
|
||||
std::vector <Att> annos;
|
||||
task.getAnnotations (annos);
|
||||
|
||||
if (annos.size ())
|
||||
description += " [" + format ((int) annos.size ()) + "]";
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue