diff --git a/ChangeLog b/ChangeLog
index 46bc94d04..8071d3259 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 ------------------------------
diff --git a/html/config.html b/html/config.html
index b241b8d92..609e36d75 100644
--- a/html/config.html
+++ b/html/config.html
@@ -210,6 +210,8 @@
diff --git a/html/task.html b/html/task.html
index f87644136..3b1893d1d 100644
--- a/html/task.html
+++ b/html/task.html
@@ -90,12 +90,14 @@
- New in version 1.4.2 (?/?/?)
+ New in version 1.4.2 (9/12/2008)
- "task undo" can now retract a "task done" command, provided no
reports have been run.
- Task now correctly sorts on entire strings, instead of just the
first character (thanks to Andy Lester).
+
- Task now uses dashes (-----) to underline column headings when
+ color is disabled (thanks to Vincent Fleuranceau).
diff --git a/src/Table.cpp b/src/Table.cpp
index e8cabef68..6de729b4b 100644
--- a/src/Table.cpp
+++ b/src/Table.cpp
@@ -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)
{
@@ -582,7 +589,57 @@ const std::string Table::formatHeader (
fg, bg,
Text::colorize (
decoration, Text::nocolor,
- pad + preJust+ data + postJust + pad) + intraPad);
+ 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);
}
////////////////////////////////////////////////////////////////////////////////
@@ -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 order;
diff --git a/src/Table.h b/src/Table.h
index 7428453ec..6a793af0c 100644
--- a/src/Table.h
+++ b/src/Table.h
@@ -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&);
void optimize (std::string&);
void sort (std::vector &);
@@ -110,6 +112,7 @@ private:
std::map mFg;
std::map mBg;
std::map mUnderline;
+ bool mDashedUnderline;
// Padding...
int mTablePadding;
diff --git a/src/report.cpp b/src/report.cpp
index e0ec8db90..c3c928b28 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -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);