diff --git a/src/Context.cpp b/src/Context.cpp index 5b7d8677e..3b6fafc37 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -56,6 +56,7 @@ Context::Context () , var_overrides ("") , cmd () , dom () +, use_color (true) , inShadow (false) , terminal_width (0) , terminal_height (0) @@ -150,7 +151,7 @@ void Context::initialize () config.set ("detection", "off"); if (! config.getBoolean ("_forcecolor")) - config.set ("color", "off"); + config.set ("color", "off"); } if (config.getBoolean ("color")) @@ -198,7 +199,7 @@ int Context::run () // Dump all debug messages. if (config.getBoolean ("debug")) foreach (d, debugMessages) - if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) + if (color ()) std::cout << colorizeDebug (*d) << "\n"; else std::cout << *d << "\n"; @@ -206,7 +207,7 @@ int Context::run () // Dump all headers. if (config.getBoolean ("verbose")) foreach (h, headers) - if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) + if (color ()) std::cout << colorizeHeader (*h) << "\n"; else std::cout << *h << "\n"; @@ -217,7 +218,7 @@ int Context::run () // Dump all footnotes. if (config.getBoolean ("verbose")) foreach (f, footnotes) - if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) + if (color ()) std::cout << colorizeFootnote (*f) << "\n"; else std::cout << *f << "\n"; @@ -317,6 +318,13 @@ int Context::dispatch (std::string &out) return rc; } +//////////////////////////////////////////////////////////////////////////////// +bool Context::color () +{ + return config.getBoolean ("color") || + config.getBoolean ("_forcecolor"); +} + //////////////////////////////////////////////////////////////////////////////// void Context::shadow () { diff --git a/src/Context.h b/src/Context.h index 47f4c3675..8e52f85db 100644 --- a/src/Context.h +++ b/src/Context.h @@ -59,6 +59,8 @@ public: int getWidth (); // determine terminal width int getHeight (); // determine terminal height + bool color (); // TTY or ? + void header (const std::string&); // Header message sink void footnote (const std::string&); // Footnote message sink void debug (const std::string&); // Debug message sink @@ -96,6 +98,7 @@ public: std::vector tagRemovals; Hooks hooks; DOM dom; + bool use_color; std::vector headers; std::vector footnotes; diff --git a/src/TDB.cpp b/src/TDB.cpp index a0a8a1809..f39ed4ced 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -744,11 +744,8 @@ void TDB::undo () Date lastChange (atoi (when.c_str ())); // Set the colors. - bool useColor = context.config.getBoolean ("color") || - context.config.getBoolean ("_forcecolor") ? true : false; - - Color color_red (useColor ? context.config.get ("color.undo.before") : ""); - Color color_green (useColor ? context.config.get ("color.undo.after") : ""); + Color color_red (context.color () ? context.config.get ("color.undo.before") : ""); + Color color_green (context.color () ? context.config.get ("color.undo.after") : ""); if (context.config.get ("undo.style") == "side") { @@ -766,8 +763,7 @@ void TDB::undo () table.addColumn ("Prior Values"); table.addColumn ("Current Values"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (1); table.setColumnUnderline (2); @@ -1147,8 +1143,6 @@ void TDB::merge (const std::string& mergeFile) } // Add some color. - bool useColor = (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) - ? true : false; Color colorAdded (context.config.get ("color.sync.added")); Color colorChanged (context.config.get ("color.sync.changed")); Color colorRejected (context.config.get ("color.sync.rejected")); @@ -1205,7 +1199,7 @@ void TDB::merge (const std::string& mergeFile) { /* std::cout << "New local task " - << (useColor ? colorAdded.colorize (lmod_it->getUuid ()) : lmod_it->getUuid ()) + << (context.color () ? colorAdded.colorize (lmod_it->getUuid ()) : lmod_it->getUuid ()) << "\n"; */ @@ -1231,7 +1225,7 @@ void TDB::merge (const std::string& mergeFile) { /* std::cout << "Adding new remote task " - << (useColor ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ()) + << (context.color () ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ()) << "\n"; */ @@ -1304,7 +1298,7 @@ void TDB::merge (const std::string& mergeFile) if (tmod_r > tmod_l) { std::cout << "Found remote change to " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << " \"" << cutOff (tmod_r.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1320,7 +1314,7 @@ void TDB::merge (const std::string& mergeFile) else { std::cout << "Retaining local changes to " - << (useColor ? colorRejected.colorize (uuid) : uuid) + << (context.color () ? colorRejected.colorize (uuid) : uuid) << " \"" << cutOff (tmod_l.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1445,7 +1439,7 @@ void TDB::merge (const std::string& mergeFile) // Update the completed record. /* std::cout << "Modifying " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << "\n"; */ @@ -1487,7 +1481,7 @@ void TDB::merge (const std::string& mergeFile) { // Update the pending record. std::cout << "Found remote change to " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1522,7 +1516,7 @@ void TDB::merge (const std::string& mergeFile) if (!found) { std::cout << "Missing " - << (useColor ? colorRejected.colorize (uuid) : uuid) + << (context.color () ? colorRejected.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getBefore ().get ("description"), 10) << "\"" << "\n"; mods.erase (current); @@ -1548,7 +1542,7 @@ void TDB::merge (const std::string& mergeFile) if (!found) { std::cout << "Merging new remote task " - << (useColor ? colorAdded.colorize (uuid) : uuid) + << (context.color () ? colorAdded.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getAfter ().get ("description"), 10) << "\"" << "\n"; diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 4b0c28ba1..03ea99e75 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -988,11 +988,8 @@ void TDB::undo () Date lastChange (atoi (when.c_str ())); // Set the colors. - bool useColor = context.config.getBoolean ("color") || - context.config.getBoolean ("_forcecolor") ? true : false; - - Color color_red (useColor ? context.config.get ("color.undo.before") : ""); - Color color_green (useColor ? context.config.get ("color.undo.after") : ""); + Color color_red (context.color () ? context.config.get ("color.undo.before") : ""); + Color color_green (context.color () ? context.config.get ("color.undo.after") : ""); if (context.config.get ("undo.style") == "side") { @@ -1010,8 +1007,7 @@ void TDB::undo () table.addColumn ("Prior Values"); table.addColumn ("Current Values"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (1); table.setColumnUnderline (2); @@ -1391,8 +1387,6 @@ void TDB::merge (const std::string& mergeFile) } // Add some color. - bool useColor = (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) - ? true : false; Color colorAdded (context.config.get ("color.sync.added")); Color colorChanged (context.config.get ("color.sync.changed")); Color colorRejected (context.config.get ("color.sync.rejected")); @@ -1449,7 +1443,7 @@ void TDB::merge (const std::string& mergeFile) { /* std::cout << "New local task " - << (useColor ? colorAdded.colorize (lmod_it->getUuid ()) : lmod_it->getUuid ()) + << (context.color () ? colorAdded.colorize (lmod_it->getUuid ()) : lmod_it->getUuid ()) << "\n"; */ @@ -1475,7 +1469,7 @@ void TDB::merge (const std::string& mergeFile) { /* std::cout << "Adding new remote task " - << (useColor ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ()) + << (context.color () ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ()) << "\n"; */ @@ -1548,7 +1542,7 @@ void TDB::merge (const std::string& mergeFile) if (tmod_r > tmod_l) { std::cout << "Found remote change to " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << " \"" << cutOff (tmod_r.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1564,7 +1558,7 @@ void TDB::merge (const std::string& mergeFile) else { std::cout << "Retaining local changes to " - << (useColor ? colorRejected.colorize (uuid) : uuid) + << (context.color () ? colorRejected.colorize (uuid) : uuid) << " \"" << cutOff (tmod_l.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1689,7 +1683,7 @@ void TDB::merge (const std::string& mergeFile) // Update the completed record. /* std::cout << "Modifying " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << "\n"; */ @@ -1731,7 +1725,7 @@ void TDB::merge (const std::string& mergeFile) { // Update the pending record. std::cout << "Found remote change to " - << (useColor ? colorChanged.colorize (uuid) : uuid) + << (context.color () ? colorChanged.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getBefore ().get ("description"), 10) << "\"" << "\n"; @@ -1766,7 +1760,7 @@ void TDB::merge (const std::string& mergeFile) if (!found) { std::cout << "Missing " - << (useColor ? colorRejected.colorize (uuid) : uuid) + << (context.color () ? colorRejected.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getBefore ().get ("description"), 10) << "\"" << "\n"; mods.erase (current); @@ -1792,7 +1786,7 @@ void TDB::merge (const std::string& mergeFile) if (!found) { std::cout << "Merging new remote task " - << (useColor ? colorAdded.colorize (uuid) : uuid) + << (context.color () ? colorAdded.colorize (uuid) : uuid) << " \"" << cutOff (tmod.getAfter ().get ("description"), 10) << "\"" << "\n"; diff --git a/src/command.cpp b/src/command.cpp index 31805a718..7fe05e905 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -267,8 +267,7 @@ int handleProjects (std::string& outs) table.addColumn ("Pri:M"); table.addColumn ("Pri:H"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -380,9 +379,6 @@ int handleTags (std::string& outs) unique[*tag] = 1; } - bool use_color = context.config.getBoolean ("color") || - context.config.getBoolean ("_forcecolor"); - if (unique.size ()) { // Render a list of tags names from the map. @@ -390,7 +386,7 @@ int handleTags (std::string& outs) table.addColumn ("Tag"); table.addColumn ("Count"); - if (use_color) + if (context.color ()) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -406,8 +402,8 @@ int handleTags (std::string& outs) table.addCell (row, 1, i->second); // Highlight the special tags. - if (use_color && (i->first == "nocolor" || - i->first == "nonag")) + if (context.color () && (i->first == "nocolor" || + i->first == "nonag")) { table.setRowColor (row, bold); } @@ -1029,13 +1025,9 @@ int handleVersion (std::string& outs) Color bold ("bold"); out << "\n" - << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) - ? bold.colorize (PACKAGE) - : PACKAGE) + << (context.color () ? bold.colorize (PACKAGE) : PACKAGE) << " " - << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) - ? bold.colorize (VERSION) - : VERSION) + << (context.color () ? bold.colorize (VERSION) : VERSION) << " built for " #if defined (DARWIN) @@ -1182,7 +1174,7 @@ int handleShow (std::string& outs) table.addColumn ("Config variable"); table.addColumn ("Value"); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -1218,7 +1210,7 @@ int handleShow (std::string& outs) table.addCell (row, 1, context.config.get (*i)); // Look for unrecognized. - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { if (std::find (unrecognized.begin (), unrecognized.end (), *i) != unrecognized.end ()) table.setRowColor (row, error); @@ -1241,7 +1233,7 @@ int handleShow (std::string& outs) foreach (i, unrecognized) out << " " << *i << "\n"; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) out << "\n These are highlighted in " << error.colorize ("color") << " above."; out << "\n\n"; @@ -1251,7 +1243,7 @@ int handleShow (std::string& outs) { out << "Some of your .taskrc variables differ from the default values."; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) out << " These are highlighted in " << warning.colorize ("color") << " above."; } @@ -2300,9 +2292,7 @@ void handleShell () { // Display some kind of welcome message. Color bold (Color::nocolor, Color::nocolor, false, true, false); - std::cout << ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) - ? bold.colorize (PACKAGE_STRING) - : PACKAGE_STRING) + std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING) << " shell\n\n" << "Enter any task command (such as 'list'), or hit 'Enter'.\n" << "There is no need to include the 'task' command itself.\n" @@ -2371,7 +2361,7 @@ int handleColor (std::string& outs) int rc = 0; std::stringstream out; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { // If the description contains 'legend', show all the colors currently in // use. @@ -2387,8 +2377,7 @@ int handleColor (std::string& outs) table.addColumn ("Color"); table.addColumn ("Definition"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); diff --git a/src/custom.cpp b/src/custom.cpp index d2a04337d..2d99959cc 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -545,8 +545,7 @@ int handleCustomReport (const std::string& report, std::string& outs) // Common to all columns. // Add underline. - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) table.setColumnUnderline (columnCount); else table.setTableDashedUnderline (); @@ -613,7 +612,7 @@ int handleCustomReport (const std::string& report, std::string& outs) } // Now auto colorize all rows. - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { for (unsigned int row = 0; row < tasks.size (); ++row) { @@ -624,7 +623,7 @@ int handleCustomReport (const std::string& report, std::string& outs) } // If an alternating row color is specified, notify the table. - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { Color alternate (context.config.get ("color.alternate")); if (alternate.nontrivial ()) @@ -633,8 +632,7 @@ int handleCustomReport (const std::string& report, std::string& outs) // How many lines taken up by table header? int table_header; - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) table_header = 1; // Underlining doesn't use extra line. else table_header = 2; // Dashes use an extra line. diff --git a/src/history.cpp b/src/history.cpp index cf466aa90..08dd8852f 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -93,8 +93,7 @@ int handleReportHistoryMonthly (std::string& outs) table.addColumn ("Deleted"); table.addColumn ("Net"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -157,7 +156,7 @@ int handleReportHistoryMonthly (std::string& outs) } table.addCell (row, 5, net); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && net) + if (context.color () && net) table.setCellColor (row, 5, net > 0 ? Color (Color::red) : Color (Color::green)); } @@ -168,7 +167,7 @@ int handleReportHistoryMonthly (std::string& outs) row = table.addRow (); table.addCell (row, 1, "Average"); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) table.setRowColor (row, Color (Color::nocolor, Color::nocolor, false, true, false)); table.addCell (row, 2, totalAdded / (table.rowCount () - 2)); table.addCell (row, 3, totalCompleted / (table.rowCount () - 2)); @@ -248,8 +247,7 @@ int handleReportHistoryAnnual (std::string& outs) table.addColumn ("Deleted"); table.addColumn ("Net"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -310,7 +308,7 @@ int handleReportHistoryAnnual (std::string& outs) } table.addCell (row, 4, net); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && net) + if (context.color () && net) table.setCellColor (row, 4, net > 0 ? Color (Color::red) : Color (Color::green)); } @@ -321,7 +319,7 @@ int handleReportHistoryAnnual (std::string& outs) row = table.addRow (); table.addCell (row, 0, "Average"); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) table.setRowColor (row, Color (Color::nocolor, Color::nocolor, false, true, false)); table.addCell (row, 1, totalAdded / (table.rowCount () - 2)); table.addCell (row, 2, totalCompleted / (table.rowCount () - 2)); @@ -401,8 +399,7 @@ int handleReportGHistoryMonthly (std::string& outs) table.addColumn ("Month"); table.addColumn ("Number Added/Completed/Deleted"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -461,7 +458,7 @@ int handleReportGHistoryMonthly (std::string& outs) unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; std::string bar = ""; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { std::string aBar = ""; if (addedGroup[i->first]) @@ -514,7 +511,7 @@ int handleReportGHistoryMonthly (std::string& outs) << table.render () << "\n"; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) out << "Legend: " << color_add.colorize ("added") << ", " @@ -592,8 +589,7 @@ int handleReportGHistoryAnnual (std::string& outs) table.addColumn ("Year"); table.addColumn ("Number Added/Completed/Deleted"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); } @@ -650,7 +646,7 @@ int handleReportGHistoryAnnual (std::string& outs) unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; std::string bar = ""; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { std::string aBar = ""; if (addedGroup[i->first]) @@ -702,7 +698,7 @@ int handleReportGHistoryAnnual (std::string& outs) << table.render () << "\n"; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) out << "Legend: " << color_add.colorize ("added") << ", " diff --git a/src/report.cpp b/src/report.cpp index e6674bd6f..32f3e54d6 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -410,8 +410,7 @@ int handleInfo (std::string& outs) table.addColumn ("Name"); table.addColumn ("Value"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -644,7 +643,7 @@ int handleInfo (std::string& outs) Table journal; // If an alternating row color is specified, notify the table. - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { Color alternate (context.config.get ("color.alternate")); if (alternate.nontrivial ()) @@ -660,8 +659,7 @@ int handleInfo (std::string& outs) journal.addColumn ("Date"); journal.addColumn ("Modification"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { journal.setColumnUnderline (0); journal.setColumnUnderline (1); @@ -735,7 +733,7 @@ int handleInfo (std::string& outs) journal.addCell (row, 0, "Total active time"); journal.addCell (row, 1, Duration (total_time).format ()); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) journal.setCellColor (row, 1, Color ("bold")); } } @@ -833,8 +831,7 @@ int handleReportSummary (std::string& outs) table.addColumn ("Complete"); table.addColumn ("0% 100%"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -871,7 +868,7 @@ int handleReportSummary (std::string& outs) std::string bar; std::string subbar; - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { bar += bar_color.colorize (std::string ( completedBar, ' ')); bar += bg_color.colorize (std::string (barWidth - completedBar, ' ')); @@ -942,8 +939,6 @@ int handleReportTimesheet (std::string& outs) if (context.sequence.size () == 1) quantity = context.sequence[0]; - bool color = context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor"); - std::stringstream out; for (int week = 0; week < quantity; ++week) { @@ -956,7 +951,7 @@ int handleReportTimesheet (std::string& outs) Color bold (Color::nocolor, Color::nocolor, false, true, false); out << "\n" - << (color ? bold.colorize (title) : title) + << (context.color () ? bold.colorize (title) : title) << "\n"; // Render the completed table. @@ -967,7 +962,7 @@ int handleReportTimesheet (std::string& outs) completed.addColumn ("Due"); completed.addColumn ("Description"); - if (color && context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { completed.setColumnUnderline (1); completed.setColumnUnderline (2); @@ -1003,7 +998,7 @@ int handleReportTimesheet (std::string& outs) completed.addCell (row, 2, getDueDate (*task, format)); completed.addCell (row, 3, getFullDescription (*task, "timesheet")); - if (color) + if (context.color ()) { Color c (task->get ("fg") + " " + task->get ("bg")); autoColorize (*task, c); @@ -1027,7 +1022,7 @@ int handleReportTimesheet (std::string& outs) started.addColumn ("Due"); started.addColumn ("Description"); - if (color && context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { started.setColumnUnderline (1); started.setColumnUnderline (2); @@ -1062,7 +1057,7 @@ int handleReportTimesheet (std::string& outs) started.addCell (row, 2, getDueDate (*task, format)); started.addCell (row, 3, getFullDescription (*task, "timesheet")); - if (color) + if (context.color ()) { Color c (task->get ("fg") + " " + task->get ("bg")); autoColorize (*task, c); @@ -1130,8 +1125,7 @@ std::string renderMonths ( table.addColumn ("Sa"); } - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (i + 1); table.setColumnUnderline (i + 2); @@ -1213,7 +1207,7 @@ std::string renderMonths ( if (context.config.getBoolean ("displayweeknumber")) { table.addCell (row, (8 * mpl), woy); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) table.setCellColor (row, (8 * mpl), color_weeknumber); } @@ -1227,7 +1221,7 @@ std::string renderMonths ( table.addCell (row, thisCol, d); - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { Color cellColor; @@ -1559,8 +1553,7 @@ int handleReportCalendar (std::string& outs) Color color_holiday (context.config.get ("color.calendar.holiday")); Color color_weeknumber (context.config.get ("color.calendar.weeknumber")); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("calendar.legend")) + if (context.color () && context.config.getBoolean ("calendar.legend")) out << "Legend: " << color_today.colorize ("today") << ", " @@ -1635,8 +1628,7 @@ int handleReportCalendar (std::string& outs) holTable.addColumn ("Holiday"); holTable.sortOn (0, Table::ascendingDueDate); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { holTable.setColumnUnderline (0); holTable.setColumnUnderline (1); @@ -1783,8 +1775,7 @@ int handleReportStats (std::string& outs) table.addColumn ("Category"); table.addColumn ("Data"); - if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) && - context.config.getBoolean ("fontunderline")) + if (context.color () && context.config.getBoolean ("fontunderline")) { table.setColumnUnderline (0); table.setColumnUnderline (1); @@ -1907,7 +1898,7 @@ int handleReportStats (std::string& outs) } // If an alternating row color is specified, notify the table. - if (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + if (context.color ()) { Color alternate (context.config.get ("color.alternate")); if (alternate.nontrivial ())