- Task now uses dashes (-----) to underline column headings when color is

disabled (thanks for Vincent Fleuranceau).
This commit is contained in:
Paul Beckingham 2008-09-12 11:27:25 -04:00
parent 11225eb599
commit 4abc722eff
6 changed files with 110 additions and 3 deletions

View file

@ -12,6 +12,8 @@ represents a feature release, and the Z represents a patch.
have been run (and therefore TDB::gc run)
+ Task now correctly sorts on entire strings, instead of just the first
character (thanks to Andy Lester)
+ Task now uses dashes (-----) to column underlines when color is disabled
(thanks to Vincent Fleuranceau)
------ old releases ------------------------------

View file

@ -210,6 +210,8 @@
<dt>color</dt>
<dd>
May be "on" or "off". Determines whether task uses color.
When "off", task will use dashes (-----) to underline column
headings.
</dd>
<dt>

View file

@ -90,12 +90,14 @@
</tr>
</table>
<h4>New in version 1.4.2 (?/?/?)</h4>
<h4>New in version 1.4.2 (9/12/2008)</h4>
<ul>
<li>"task undo" can now retract a "task done" command, provided no
reports have been run.
<li>Task now correctly sorts on entire strings, instead of just the
first character (thanks to Andy Lester).
<li>Task now uses dashes (-----) to underline column headings when
color is disabled (thanks to Vincent Fleuranceau).
</ul>
<p>

View file

@ -54,6 +54,7 @@
Table::Table ()
: mRows (0)
, mIntraPadding (1)
, mDashedUnderline (false)
, mTablePadding (0)
, mTableWidth (0)
, mSuppressWS (false)
@ -103,6 +104,12 @@ void Table::setTableWidth (int width)
mTableWidth = width;
}
////////////////////////////////////////////////////////////////////////////////
void Table::setTableDashedUnderline ()
{
mDashedUnderline = true;
}
////////////////////////////////////////////////////////////////////////////////
int Table::addColumn (const std::string& col)
{
@ -585,6 +592,56 @@ const std::string Table::formatHeader (
pad + preJust + data + postJust + pad) + intraPad);
}
////////////////////////////////////////////////////////////////////////////////
// data One Data to be rendered
// width 8 Max data width for column/specified width
// padding 1 Extra padding around data
// intraPadding 0 Extra padding between columns only
// justification right Alignment withing padding
//
// Returns:
// "------- "
// ------- data
// ^ ^ padding
// ^ intraPadding
// ^^^^^^^^ width
// ^ ^ fg/bg
//
const std::string Table::formatHeaderDashedUnderline (
int col,
int width,
int padding)
{
assert (width > 0);
Text::color fg = getHeaderFg (col);
Text::color bg = getHeaderBg (col);
Text::color decoration = getHeaderUnderline (col);
std::string data = "";
for (int i = 0; i < width; ++i)
data += '-';
std::string pad = "";
std::string intraPad = "";
std::string attrOn = "";
std::string attrOff = "";
for (int i = 0; i < padding; ++i)
pad += " ";
// Place the value within the available space - justify.
if (col < (signed) mColumns.size () - 1)
for (int i = 0; i < getIntraPadding (); ++i)
intraPad += " ";
return Text::colorize (
fg, bg,
Text::colorize (
decoration, Text::nocolor,
pad + data + pad) + intraPad);
}
////////////////////////////////////////////////////////////////////////////////
void Table::formatCell (
const int row,
@ -861,13 +918,24 @@ const std::string Table::render ()
// Print column headers in column order.
std::string output;
std::string underline;
for (size_t col = 0; col < mColumns.size (); ++col)
{
output += formatHeader (
col,
mCalculatedWidth[col],
mColumnPadding[col]);
if (mDashedUnderline)
underline += formatHeaderDashedUnderline (
col,
mCalculatedWidth[col],
mColumnPadding[col]);
}
output += "\n";
if (underline.length ())
output += underline + "\n";
// Determine row order, according to sort options.
std::vector <int> order;

View file

@ -51,6 +51,7 @@ public:
void setTablePadding (int);
void setTableIntraPadding (int);
void setTableWidth (int);
void setTableDashedUnderline ();
int addColumn (const std::string&);
void setColumnColor (int, Text::color, Text::color);
@ -98,6 +99,7 @@ private:
just getJustification (const int, const int);
just getHeaderJustification (const int);
const std::string formatHeader (const int, const int, const int);
const std::string formatHeaderDashedUnderline (const int, const int, const int);
void formatCell (const int, const int, const int, const int, std::vector <std::string>&, std::string&);
void optimize (std::string&);
void sort (std::vector <int>&);
@ -110,6 +112,7 @@ private:
std::map <std::string, std::string> mFg;
std::map <std::string, std::string> mBg;
std::map <std::string, std::string> mUnderline;
bool mDashedUnderline;
// Padding...
int mTablePadding;

View file

@ -143,7 +143,7 @@ void handleList (TDB& tdb, T& task, Config& conf)
if (showAge) table.addColumn ("Age");
table.addColumn ("Description");
if (conf.get ("color", true))
if (conf.get (std::string ("color"), true))
{
table.setColumnUnderline (0);
table.setColumnUnderline (1);
@ -153,6 +153,8 @@ void handleList (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (5);
if (showAge) table.setColumnUnderline (6);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -291,6 +293,8 @@ void handleSmallList (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (2);
table.setColumnUnderline (3);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -414,6 +418,8 @@ void handleCompleted (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (1);
table.setColumnUnderline (2);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -493,6 +499,8 @@ void handleInfo (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (0);
table.setColumnUnderline (1);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -710,6 +718,8 @@ void handleLongList (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (7);
if (showAge) table.setColumnUnderline (8);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -913,6 +923,8 @@ void handleReportSummary (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (2);
table.setColumnUnderline (3);
}
else
table.setTableDashedUnderline ();
table.setColumnJustification (1, Table::right);
table.setColumnJustification (2, Table::right);
@ -1056,6 +1068,8 @@ void handleReportNext (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (5);
if (showAge) table.setColumnUnderline (6);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -1275,6 +1289,8 @@ void handleReportHistory (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (4);
table.setColumnUnderline (5);
}
else
table.setTableDashedUnderline ();
table.setColumnJustification (2, Table::right);
table.setColumnJustification (3, Table::right);
@ -1462,6 +1478,8 @@ void handleReportGHistory (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (0);
table.setColumnUnderline (1);
}
else
table.setTableDashedUnderline ();
// Determine the longest line.
int maxLine = 0;
@ -1623,6 +1641,8 @@ void handleReportUsage (const TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (0);
table.setColumnUnderline (1);
}
else
table.setTableDashedUnderline ();
table.setColumnJustification (1, Table::right);
table.sortOn (1, Table::descendingNumeric);
@ -1681,6 +1701,8 @@ std::string renderMonths (
table.setColumnUnderline (i + 6);
table.setColumnUnderline (i + 7);
}
else
table.setTableDashedUnderline ();
table.setColumnJustification (i + 0, Table::right);
table.setColumnJustification (i + 1, Table::right);
@ -1896,6 +1918,8 @@ void handleReportActive (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (3);
table.setColumnUnderline (4);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -2011,6 +2035,8 @@ void handleReportOverdue (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (3);
table.setColumnUnderline (4);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -2126,6 +2152,8 @@ void handleReportOldest (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (5);
if (showAge) table.setColumnUnderline (6);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);
@ -2269,6 +2297,8 @@ void handleReportNewest (TDB& tdb, T& task, Config& conf)
table.setColumnUnderline (5);
if (showAge) table.setColumnUnderline (6);
}
else
table.setTableDashedUnderline ();
table.setColumnWidth (0, Table::minimum);
table.setColumnWidth (1, Table::minimum);