- Documented the new layout algorithm.
- Used Nibbler for decomposing fields into word chunks.
- Implemented variable intra padding.
- Implemented variable left margin.
- Implemented variable extra padding.
- Implemented colored headers.
- Implemented wrappable headers.
- Eliminated need to specify fixed column size.
This commit is contained in:
Paul Beckingham 2011-04-29 01:45:10 -04:00
parent 66afc7c057
commit 4dca2a5a2d
9 changed files with 186 additions and 87 deletions

View file

@ -25,9 +25,6 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <iomanip>
#include <sstream>
#include <math.h>
#include <Context.h>
#include <ColID.h>
@ -61,22 +58,19 @@ void ColumnID::measure (Task& task, int& minimum, int& maximum)
else length = (int) log10 ((double) task.id); // Slow
minimum = maximum = length;
std::cout << "# ColID::measure id=" << task.id << " min=" << minimum << " max=" << maximum << "\n";
}
////////////////////////////////////////////////////////////////////////////////
void ColumnID::render (std::vector <std::string>& lines, Task& task, int width)
void ColumnID::render (
std::vector <std::string>& lines,
Task& task,
int width,
Color& color)
{
std::stringstream line;
line << std::setw (width) << std::setfill (' ') << task.id;
if (task.id)
line << task.id;
lines.push_back (color.colorize (rightJustify (task.id, width)));
else
line << '-';
lines.push_back (line.str ());
lines.push_back (color.colorize (rightJustify ("-", width)));
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -30,6 +30,7 @@
#include <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnID : public Column
@ -39,7 +40,7 @@ public:
~ColumnID ();
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};

View file

@ -25,10 +25,10 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <math.h>
#include <Context.h>
#include <Nibbler.h>
#include <ColProject.h>
#include <text.h>
extern Context context;
@ -50,36 +50,34 @@ ColumnProject::~ColumnProject ()
void ColumnProject::measure (Task& task, int& minimum, int& maximum)
{
std::string project = task.get ("project");
minimum = maximum = project.length ();
std::string::size_type space = project.find (' ');
if (space == std::string::npos)
{
std::cout << "# ColProject::measure project=" << project << " min=" << minimum << " max=" << maximum << "\n";
return;
}
minimum = 0;
int longest = 0;
std::string::size_type last = -1;
while (space != std::string::npos)
maximum = project.length ();
Nibbler nibbler (project);
std::string word;
while (nibbler.getUntilWS (word))
{
if (space - last - 1 > longest)
longest = space - last - 1;
last = space;
space = project.find (' ', last + 1);
nibbler.skipWS ();
if (word.length () > minimum)
minimum = word.length ();
}
if (longest)
minimum = longest;
std::cout << "# ColProject::measure project=" << project << " min=" << minimum << " max=" << maximum << "\n";
}
////////////////////////////////////////////////////////////////////////////////
void ColumnProject::render (std::vector <std::string>& lines, Task& task, int width)
void ColumnProject::render (
std::vector <std::string>& lines,
Task& task,
int width,
Color& color)
{
// TODO Can't use Nibbler here. Need to use a UTF8-safe version of extractLines.
Nibbler nibbler (task.get ("project"));
std::string word;
while (nibbler.getUntilWS (word))
{
nibbler.skipWS ();
lines.push_back (color.colorize (leftJustify (word, width)));
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -30,6 +30,7 @@
#include <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnProject : public Column
@ -39,7 +40,7 @@ public:
~ColumnProject ();
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};

View file

@ -25,7 +25,6 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <Context.h>
#include <Column.h>
#include <ColID.h>
@ -87,27 +86,29 @@ Column::~Column ()
}
////////////////////////////////////////////////////////////////////////////////
void Column::renderHeader (std::vector <std::string>& lines, int width)
void Column::renderHeader (
std::vector <std::string>& lines,
int width,
Color& color)
{
// Create a basic label.
std::string header;
header.reserve (width);
header = _label;
// Right pad with spaces, if necessary.
int length = characters (_label);
if (length < width)
_label += std::string (' ', width - length);
// Create a fungible copy.
Color c = color;
// Now underline the header, or add a dashed line.
if (context.config.getBoolean ("fontunderline"))
{
lines.push_back (header);
c.blend (Color (Color::nocolor, Color::nocolor, true, false, false));
lines.push_back (c.colorize (leftJustify (header, width)));
}
else
{
lines.push_back (header);
lines.push_back (std::string ('-', width));
lines.push_back (c.colorize (leftJustify (header, width)));
lines.push_back (c.colorize (std::string (width, '-')));
}
}

View file

@ -29,6 +29,7 @@
#include <vector>
#include <string>
#include <Color.h>
#include <Task.h>
class Column
@ -49,8 +50,8 @@ public:
std::string type () const { return _type; }
virtual void measure (Task&, int&, int&) = 0;
virtual void renderHeader (std::vector <std::string>&, int);
virtual void render (std::vector <std::string>&, Task&, int) = 0;
virtual void renderHeader (std::vector <std::string>&, int, Color&);
virtual void render (std::vector <std::string>&, Task&, int, Color&) = 0;
protected:
std::string _type;