mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Feature - #292 Alternate line coloration
- Implemented alternate line coloration, triggered by the 'color.alternate' configuration variable.
This commit is contained in:
parent
3cd45c3acd
commit
175dd3eb4f
5 changed files with 26 additions and 6 deletions
|
@ -2,6 +2,8 @@
|
|||
------ current release ---------------------------
|
||||
|
||||
1.9.0 ()
|
||||
+ Added feature #292 that permits alternate line coloration in reports
|
||||
(thanks to Richard Querin).
|
||||
|
||||
------ old releases ------------------------------
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ static struct
|
|||
} allColors[] =
|
||||
{
|
||||
// Color.h enum i18n.h English Index
|
||||
{ Color::nocolor, 0, "", 0},
|
||||
{ Color::nocolor, 0, "none", 0},
|
||||
{ Color::black, COLOR_BLACK, "black", 1}, // fg 29+0 bg 39+0
|
||||
{ Color::red, COLOR_RED, "red", 2},
|
||||
{ Color::green, COLOR_GREEN, "green", 3},
|
||||
|
@ -110,7 +110,7 @@ Color::Color (const std::string& spec)
|
|||
std::vector <std::string>::iterator it;
|
||||
for (it = words.begin (); it != words.end (); ++it)
|
||||
{
|
||||
word = lowerCase (*it);
|
||||
word = lowerCase (trim (*it));
|
||||
|
||||
if (word == "bold")
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ Color::Color (const std::string& spec)
|
|||
|
||||
value |= _COLOR_256;
|
||||
}
|
||||
else
|
||||
else if (word != "")
|
||||
throw std::string ("The color '") + *it + "' is not recognized.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,12 @@ void Table::setTableColor (const Color& c)
|
|||
mColor["table"] = c;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setTableAlternateColor (const Color& c)
|
||||
{
|
||||
mColor["alternate"] = c;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setTablePadding (int padding)
|
||||
{
|
||||
|
@ -177,7 +183,7 @@ void Table::setRowColor (const int row, const Color& c)
|
|||
{
|
||||
char id[12];
|
||||
sprintf (id, "row:%d", row);
|
||||
mColor[id] = c;
|
||||
mColor[id].blend (c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -568,7 +574,7 @@ void Table::formatCell (
|
|||
{
|
||||
assert (width > 0);
|
||||
|
||||
Color c = getColor (row, col);
|
||||
Color c = getColor (row, col);
|
||||
just justification = getJustification (row, col);
|
||||
std::string data = getCell (row, col);
|
||||
|
||||
|
@ -964,6 +970,13 @@ const std::string Table::render (int maximum /* = 0 */)
|
|||
if (mSortColumns.size ())
|
||||
sort (order);
|
||||
|
||||
// Now blend in the alternate row color.
|
||||
Color alternate = mColor["alternate"];
|
||||
if (alternate.nontrivial ())
|
||||
for (unsigned int row = 0; row < order.size (); ++row)
|
||||
if (row % 2)
|
||||
setRowColor (order[row], alternate);
|
||||
|
||||
// If a non-zero maximum is specified, then it limits the number of rows of
|
||||
// the table that are rendered.
|
||||
int limit = mRows;
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
Table& operator= (const Table&);
|
||||
|
||||
void setTableColor (const Color&);
|
||||
void setTableAlternateColor (const Color&);
|
||||
void setTablePadding (int);
|
||||
void setTableIntraPadding (int);
|
||||
void setTableWidth (int);
|
||||
|
|
|
@ -101,7 +101,6 @@ int handleCustomReport (const std::string& report, std::string &outs)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// This report will eventually become the one report that many others morph into
|
||||
// via the .taskrc file.
|
||||
|
||||
int runCustomReport (
|
||||
const std::string& report,
|
||||
const std::string& columnList,
|
||||
|
@ -530,6 +529,11 @@ int runCustomReport (
|
|||
}
|
||||
}
|
||||
|
||||
// If an alternating row color is specified, notify the table.
|
||||
Color alternate (context.config.get ("color.alternate", ""));
|
||||
if (alternate.nontrivial ())
|
||||
table.setTableAlternateColor (alternate);
|
||||
|
||||
// Limit the number of rows according to the report definition.
|
||||
int maximum = context.config.get (std::string ("report.") + report + ".limit", (int)0);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue