From 175dd3eb4f2d5ee799c0bcb8a91d479ba6544abf Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 5 Oct 2009 22:09:19 -0400 Subject: [PATCH] Feature - #292 Alternate line coloration - Implemented alternate line coloration, triggered by the 'color.alternate' configuration variable. --- ChangeLog | 2 ++ src/Color.cpp | 6 +++--- src/Table.cpp | 17 +++++++++++++++-- src/Table.h | 1 + src/custom.cpp | 6 +++++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fcb6daf3..e171fe8e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 ------------------------------ diff --git a/src/Color.cpp b/src/Color.cpp index 56212efc8..9dca6bc07 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -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 ::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."; } } diff --git a/src/Table.cpp b/src/Table.cpp index f36a53825..ff7c931e2 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -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; diff --git a/src/Table.h b/src/Table.h index 1cd44818e..3c8217616 100644 --- a/src/Table.h +++ b/src/Table.h @@ -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); diff --git a/src/custom.cpp b/src/custom.cpp index c42254e9e..8b76c5317 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -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);