TW-101 - New description column format: Truncated WITH annotation count

Adds a "truncated with annotation count" column style for the
description field and corresponding unit test.
This commit is contained in:
atomicules 2014-08-17 21:58:19 +01:00 committed by Paul Beckingham
parent 7c6618e50a
commit 87f9d548df
4 changed files with 142 additions and 0 deletions

View file

@ -49,6 +49,7 @@ ColumnDescription::ColumnDescription ()
_styles.push_back ("oneline");
_styles.push_back ("truncated");
_styles.push_back ("count");
_styles.push_back ("truncated_count");
_dateformat = context.config.get ("dateformat.annotation");
if (_dateformat == "")
@ -74,6 +75,7 @@ ColumnDescription::ColumnDescription ()
+ " " + t + " " + a4);
_examples.push_back (d.substr (0, 20) + "...");
_examples.push_back (d + " [4]");
_examples.push_back (d.substr (0, 20) + "... [4]");
_hyphenate = context.config.getBoolean ("hyphenate");
@ -163,6 +165,13 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
minimum = longestWord (description);
}
// The te... [2]
else if (_style == "truncated_count")
{
minimum = 4;
maximum = utf8_width (description) + 1 + 1 + format (task.annotation_count).length () + 1;
}
else
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
}
@ -262,6 +271,29 @@ void ColumnDescription::render (
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
}
// This is a des... [2]
else if (_style == "truncated_count")
{
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
int len = utf8_width (description);
std::string annos_count;
int len_annos = 0;
if (annos.size ())
{
annos_count = " [" + format ((int) annos.size ()) + "]";
len_annos = utf8_width (annos_count);
len += len_annos;
}
if (len > width)
lines.push_back (color.colorize (description.substr (0, width - len_annos - 3) + "..." + annos_count));
else
lines.push_back (color.colorize (leftJustify (description + annos_count, width)));
}
}
////////////////////////////////////////////////////////////////////////////////