- Implemented new string formats: left_fixed and right_fixed, which
  do not word-wrap.  This is used for the history report.
This commit is contained in:
Paul Beckingham 2011-05-13 18:03:06 -04:00
parent 291818c33d
commit 4f8c503a04
2 changed files with 17 additions and 7 deletions

View file

@ -25,7 +25,6 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <Context.h>
#include <ColString.h>
#include <text.h>
@ -58,13 +57,17 @@ void ColumnString::setReport (const std::string& value)
//
void ColumnString::measure (const std::string& value, int& minimum, int& maximum)
{
std::string stripped = Color::strip (value);
maximum = stripped.length ();
if (_style == "left" ||
_style == "right" ||
_style == "default")
{
std::string stripped = Color::strip (value);
maximum = stripped.length ();
minimum = longestWord (stripped);
}
else if (_style == "left_fixed" ||
_style == "right_fixed")
minimum = maximum = strippedLength (value);
else
throw std::string ("Unrecognized column format 'string.") + _style + "'";
}
@ -94,6 +97,14 @@ void ColumnString::render (
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (rightJustify (*i, width)));
}
else if (_style == "left_fixed")
{
lines.push_back (leftJustify (value, width));
}
else if (_style == "right_fixed")
{
lines.push_back (rightJustify (value, width));
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -26,7 +26,6 @@
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <Context.h>
#include <ViewText.h>
#include <text.h>
@ -551,13 +550,13 @@ int handleReportGHistoryAnnual (std::string& outs)
}
}
int widthOfBar = context.getWidth () - 5; // 5 == strlen ("2008 ")
int widthOfBar = context.getWidth () - 5; // 5 == strlen ("YYYY ")
// Now build the view.
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", "Year"));
view.add (Column::factory ("string", "Number Added/Completed/Deleted"));
view.add (Column::factory ("string.left_fixed", "Number Added/Completed/Deleted"));
Color color_add (context.config.get ("color.history.add"));
Color color_done (context.config.get ("color.history.done"));