本文整理汇总了C++中ViewText::colorHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ ViewText::colorHeader方法的具体用法?C++ ViewText::colorHeader怎么用?C++ ViewText::colorHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewText
的用法示例。
在下文中一共展示了ViewText::colorHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
//.........这里部分代码省略.........
daysPending += (end - entry) / 86400.0;
}
if (status == Task::pending)
daysPending += (now.toEpoch () - entry) / 86400.0;
descLength += task->get ("description").length ();
std::map <std::string, std::string> annotations;
task->getAnnotations (annotations);
annotationsT += annotations.size ();
std::vector <std::string> tags;
task->getTags (tags);
if (tags.size ()) ++taggedT;
std::vector <std::string>::iterator t;
for (t = tags.begin (); t != tags.end (); ++t)
allTags[*t] = 0;
std::string project = task->get ("project");
if (project != "")
allProjects[project] = 0;
}
// Create a table for output.
ViewText view;
view.width (context.getWidth ());
view.intraPadding (2);
view.add (Column::factory ("string", STRING_CMD_STATS_CATEGORY));
view.add (Column::factory ("string", STRING_CMD_STATS_DATA));
Color label (context.config.get ("color.label"));
view.colorHeader (label);
int row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STAT_PE);
view.set (row, 1, pendingT);
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STAT_WA);
view.set (row, 1, waitingT);
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STAT_RE);
view.set (row, 1, recurringT);
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STAT_CO);
view.set (row, 1, completedT);
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STAT_DE);
view.set (row, 1, deletedT);
row = view.addRow ();
view.set (row, 0, STRING_CMD_STATS_TOTAL);
view.set (row, 1, totalT);
row = view.addRow ();
view.set (row, 0, STRING_CMD_STATS_ANNOTATIONS);
view.set (row, 1, annotationsT);
row = view.addRow ();
view.set (row, 0, STRING_CMD_STATS_UNIQUE_TAGS);
view.set (row, 1, (int)allTags.size ());
示例2: lastChange
void TDB2::show_diff (
const std::string& current,
const std::string& prior,
const std::string& when)
{
ISO8601d lastChange (strtol (when.c_str (), NULL, 10));
// Set the colors.
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")
{
std::cout << "\n"
<< format (STRING_TDB2_LAST_MOD, lastChange.toString ())
<< "\n";
// Attributes are all there is, so figure the different attribute names
// between before and after.
ViewText view;
view.width (context.getWidth ());
view.intraPadding (2);
view.add (Column::factory ("string", ""));
view.add (Column::factory ("string", STRING_TDB2_UNDO_PRIOR));
view.add (Column::factory ("string", STRING_TDB2_UNDO_CURRENT));
Color label (context.config.get ("color.label"));
view.colorHeader (label);
Task after (current);
if (prior != "")
{
Task before (prior);
std::vector <std::string> beforeAtts;
for (auto& att : before)
beforeAtts.push_back (att.first);
std::vector <std::string> afterAtts;
for (auto& att : after)
afterAtts.push_back (att.first);
std::vector <std::string> beforeOnly;
std::vector <std::string> afterOnly;
listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly);
int row;
for (auto& name : beforeOnly)
{
row = view.addRow ();
view.set (row, 0, name);
view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
}
for (auto& att : before)
{
std::string priorValue = before.get (att.first);
std::string currentValue = after.get (att.first);
if (currentValue != "")
{
row = view.addRow ();
view.set (row, 0, att.first);
view.set (row, 1, renderAttribute (att.first, priorValue),
(priorValue != currentValue ? color_red : Color ()));
view.set (row, 2, renderAttribute (att.first, currentValue),
(priorValue != currentValue ? color_green : Color ()));
}
}
for (auto& name : afterOnly)
{
row = view.addRow ();
view.set (row, 0, name);
view.set (row, 2, renderAttribute (name, after.get (name)), color_green);
}
}
else
{
int row;
for (auto& att : after)
{
row = view.addRow ();
view.set (row, 0, att.first);
view.set (row, 2, renderAttribute (att.first, after.get (att.first)), color_green);
}
}
std::cout << "\n"
<< view.render ()
<< "\n";
}
// This style looks like this:
// --- before 2009-07-04 00:00:25.000000000 +0200
// +++ after 2009-07-04 00:00:45.000000000 +0200
//
// - name: old // att deleted
// + name:
//.........这里部分代码省略.........
示例3: execute
////////////////////////////////////////////////////////////////////////////////
// Project Remaining Avg Age Complete 0% 100%
// A 12 13d 55% XXXXXXXXXXXXX-----------
// B 109 3d 12h 10% XXX---------------------
int CmdSummary::execute (std::string& output)
{
int rc = 0;
// Scan the pending tasks.
handleRecurrence ();
// Apply filter.
std::vector <Task> filtered;
filter (filtered);
context.tdb2.commit ();
// Generate unique list of project names from all pending tasks.
std::map <std::string, bool> allProjects;
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)
if (task->getStatus () == Task::pending)
allProjects[task->get ("project")] = false;
// Initialize counts, sum.
std::map <std::string, int> countPending;
std::map <std::string, int> countCompleted;
std::map <std::string, double> sumEntry;
std::map <std::string, int> counter;
time_t now = time (NULL);
// Initialize counters.
std::map <std::string, bool>::iterator project;
for (project = allProjects.begin (); project != allProjects.end (); ++project)
{
countPending [project->first] = 0;
countCompleted [project->first] = 0;
sumEntry [project->first] = 0.0;
counter [project->first] = 0;
}
// Count the various tasks.
for (task = filtered.begin (); task != filtered.end (); ++task)
{
std::string project = task->get ("project");
++counter[project];
if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{
++countPending[project];
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
if (entry)
sumEntry[project] = sumEntry[project] + (double) (now - entry);
}
else if (task->getStatus () == Task::completed)
{
++countCompleted[project];
time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
time_t end = strtol (task->get ("end").c_str (), NULL, 10);
if (entry && end)
sumEntry[project] = sumEntry[project] + (double) (end - entry);
}
}
// Create a table for output.
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", STRING_CMD_SUMMARY_PROJECT));
view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_REMAINING));
view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_AVG_AGE));
view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_COMPLETE));
view.add (Column::factory ("string.left_fixed", "0% 100%"));
Color bar_color (context.config.get ("color.summary.bar"));
Color bg_color (context.config.get ("color.summary.background"));
Color label (context.config.get ("color.label"));
view.colorHeader (label);
int barWidth = 30;
std::vector <std::string> processed;
std::map <std::string, bool>::iterator i;
for (i = allProjects.begin (); i != allProjects.end (); ++i)
{
if (countPending[i->first] > 0)
{
const std::vector <std::string> parents = extractParents (i->first);
std::vector <std::string>::const_iterator parent;
for (parent = parents.begin (); parent != parents.end (); parent++)
{
if (std::find (processed.begin (), processed.end (), *parent)
== processed.end ())
{
int row = view.addRow ();
view.set (row, 0, indentProject (*parent));
processed.push_back (*parent);
//.........这里部分代码省略.........
示例4: execute
//.........这里部分代码省略.........
}
int details_dFrom = Date::daysInMonth (details_mFrom, details_yFrom);
++mTo;
if (mTo == 13)
{
mTo = 1;
++yTo;
}
Date date_after (details_mFrom, details_dFrom, details_yFrom);
std::string after = date_after.toString (context.config.get ("dateformat"));
Date date_before (mTo, 1, yTo);
std::string before = date_before.toString (context.config.get ("dateformat"));
// Table with due date information
if (context.config.get ("calendar.details") == "full")
{
// Assert that 'report' is a valid report.
std::string report = context.config.get ("calendar.details.report");
if (context.commands.find (report) == context.commands.end ())
throw std::string (STRING_ERROR_DETAILS);
// If the executable was "cal" or equivalent, replace it with "task".
std::string executable = context.cli._args[0].attribute ("raw");
std::string::size_type cal = executable.find ("cal");
if (cal != std::string::npos)
executable = executable.substr (0, cal) + PACKAGE;
std::vector <std::string> args;
args.push_back ("rc:" + context.rc_file._data);
args.push_back ("rc.due:0");
args.push_back ("rc.verbose:label,affected,blank");
args.push_back ("due.after:" + after);
args.push_back ("due.before:" + before);
args.push_back ("-nocal");
args.push_back (report);
std::string output;
::execute (executable, args, "", output);
out << output;
}
// Table with holiday information
if (context.config.get ("calendar.holidays") == "full")
{
ViewText holTable;
holTable.width (context.getWidth ());
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_DATE));
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL));
holTable.colorHeader (color_label);
Config::const_iterator it;
std::map <time_t, std::vector<std::string>> hm; // we need to store multiple holidays per day
for (it = context.config.begin (); it != context.config.end (); ++it)
if (it->first.substr (0, 8) == "holiday.")
if (it->first.substr (it->first.size () - 4) == "name")
{
std::string holName = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".date");
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
if (date_after < hDate && hDate < date_before)
{
hm[hDate.toEpoch()].push_back(holName);
}
}
std::string format = context.config.get ("report." +
context.config.get ("calendar.details.report") +
".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
std::map <time_t, std::vector<std::string>>::iterator hm_it;
for (hm_it = hm.begin(); hm_it != hm.end(); ++hm_it)
{
std::vector <std::string> v = hm_it->second;
Date hDate (hm_it->first);
std::string d = hDate.toString (format);
for (size_t i = 0; i < v.size(); i++)
{
int row = holTable.addRow ();
holTable.set (row, 0, d);
holTable.set (row, 1, v[i]);
}
}
out << optionalBlankLine ()
<< holTable.render ()
<< "\n";
}
}
output = out.str ();
return rc;
}
示例5: renderMonths
std::string CmdCalendar::renderMonths (
int firstMonth,
int firstYear,
const Date& today,
std::vector <Task>& all,
int monthsPerLine)
{
// What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1)
throw std::string (STRING_CMD_CAL_SUN_MON);
// Build table for the number of months to be displayed.
Color label (context.config.get ("color.label"));
ViewText view;
view.colorHeader (label);
view.width (context.getWidth ());
for (int i = 0 ; i < (monthsPerLine * 8); i += 8)
{
if (weekStart == 1)
{
view.add (Column::factory ("string.right", " "));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
}
else
{
view.add (Column::factory ("string.right", " "));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
}
}
// At most, we need 6 rows.
view.addRow ();
view.addRow ();
view.addRow ();
view.addRow ();
view.addRow ();
view.addRow ();
// Set number of days per month, months to render, and years to render.
std::vector<int> years;
std::vector<int> months;
std::vector<int> daysInMonth;
int thisYear = firstYear;
int thisMonth = firstMonth;
for (int i = 0 ; i < monthsPerLine ; i++)
{
if (thisMonth < 13)
{
years.push_back (thisYear);
}
else
{
thisMonth -= 12;
years.push_back (++thisYear);
}
months.push_back (thisMonth);
daysInMonth.push_back (Date::daysInMonth (thisMonth++, thisYear));
}
int row = 0;
Color color_today (context.config.get ("color.calendar.today"));
Color color_due (context.config.get ("color.calendar.due"));
Color color_duetoday (context.config.get ("color.calendar.due.today"));
Color color_overdue (context.config.get ("color.calendar.overdue"));
Color color_weekend (context.config.get ("color.calendar.weekend"));
Color color_holiday (context.config.get ("color.calendar.holiday"));
Color color_weeknumber (context.config.get ("color.calendar.weeknumber"));
// Loop through months to be added on this line.
for (int mpl = 0; mpl < monthsPerLine ; mpl++)
{
// Reset row counter for subsequent months
if (mpl != 0)
row = 0;
// Loop through days in month and add to table.
for (int d = 1; d <= daysInMonth[mpl]; ++d)
{
Date temp (months[mpl], d, years[mpl]);
int dow = temp.dayOfWeek ();
int woy = temp.weekOfYear (weekStart);
if (context.config.getBoolean ("displayweeknumber"))
view.set (row, (8 * mpl), woy, color_weeknumber);
//.........这里部分代码省略.........
示例6: execute
int CmdGHistoryAnnual::execute (std::string& output)
{
int rc = 0;
std::map <time_t, int> groups; // Represents any month with data
std::map <time_t, int> addedGroup; // Additions by month
std::map <time_t, int> completedGroup; // Completions by month
std::map <time_t, int> deletedGroup; // Deletions by month
// Apply filter.
handleRecurrence ();
Filter filter;
std::vector <Task> filtered;
filter.subset (filtered);
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)
{
Date entry (task->get_date ("entry"));
Date end;
if (task->has ("end"))
end = Date (task->get_date ("end"));
time_t epoch = entry.startOfYear ().toEpoch ();
groups[epoch] = 0;
// Every task has an entry date.
++addedGroup[epoch];
// All deleted tasks have an end date.
if (task->getStatus () == Task::deleted)
{
epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0;
++deletedGroup[epoch];
}
// All completed tasks have an end date.
else if (task->getStatus () == Task::completed)
{
epoch = end.startOfYear ().toEpoch ();
groups[epoch] = 0;
++completedGroup[epoch];
}
}
int widthOfBar = context.getWidth () - 5; // 5 == strlen ("YYYY ")
// Now build the view.
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", STRING_CMD_GHISTORY_YEAR));
view.add (Column::factory ("string.left_fixed", STRING_CMD_GHISTORY_NUMBER));
Color color_add (context.config.get ("color.history.add"));
Color color_done (context.config.get ("color.history.done"));
Color color_delete (context.config.get ("color.history.delete"));
Color label (context.config.get ("color.label"));
view.colorHeader (label);
// Determine the longest line, and the longest "added" line.
int maxAddedLine = 0;
int maxRemovedLine = 0;
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine)
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first];
if (addedGroup[i->first] > maxAddedLine)
maxAddedLine = addedGroup[i->first];
}
int maxLine = maxAddedLine + maxRemovedLine;
if (maxLine > 0)
{
unsigned int leftOffset = (widthOfBar * maxAddedLine) / maxLine;
int totalAdded = 0;
int totalCompleted = 0;
int totalDeleted = 0;
int priorYear = 0;
int row = 0;
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
row = view.addRow ();
totalAdded += addedGroup[i->first];
totalCompleted += completedGroup[i->first];
totalDeleted += deletedGroup[i->first];
Date dt (i->first);
int m, d, y;
dt.toMDY (m, d, y);
if (y != priorYear)
{
//.........这里部分代码省略.........