- Integrated Damian Glenny's changes

This commit is contained in:
Paul Beckingham 2008-06-15 18:38:01 -04:00
parent c393d47cdf
commit d1ef0d17d5

View file

@ -240,7 +240,6 @@ int main (int argc, char** argv)
std::vector <std::string> args; std::vector <std::string> args;
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
args.push_back (argv[i]); args.push_back (argv[i]);
std::string command; std::string command;
T task; T task;
parse (args, command, task, conf); parse (args, command, task, conf);
@ -382,7 +381,6 @@ void handleTags (const TDB& tdb, T& task, Config& conf)
else else
std::cout << "No tags." std::cout << "No tags."
<< std::endl; << std::endl;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1839,15 +1837,20 @@ void handleReportUsage (const TDB& tdb, T& task, Config& conf)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string renderMonth ( std::string renderMonths (
int month, int firstMonth,
int year, int firstYear,
const Date& today, const Date& today,
std::vector <T>& all, std::vector <T>& all,
Config& conf) Config& conf)
{ {
Table table; Table table;
table.setDateFormat (conf.get ("dateformat", "m/d/Y")); table.setDateFormat (conf.get ("dateformat", "m/d/Y"));
int monthsPerLine = (conf.get ("monthsperline", 1));
// Build table for the number of months to be displayed.
for (int i = 0 ; i < (monthsPerLine * 8); i += 8)
{
table.addColumn (" "); table.addColumn (" ");
table.addColumn ("Su"); table.addColumn ("Su");
table.addColumn ("Mo"); table.addColumn ("Mo");
@ -1857,37 +1860,68 @@ std::string renderMonth (
table.addColumn ("Fr"); table.addColumn ("Fr");
table.addColumn ("Sa"); table.addColumn ("Sa");
table.setColumnUnderline (1); table.setColumnUnderline (i + 1);
table.setColumnUnderline (2); table.setColumnUnderline (i + 2);
table.setColumnUnderline (3); table.setColumnUnderline (i + 3);
table.setColumnUnderline (4); table.setColumnUnderline (i + 4);
table.setColumnUnderline (5); table.setColumnUnderline (i + 5);
table.setColumnUnderline (6); table.setColumnUnderline (i + 6);
table.setColumnUnderline (7); table.setColumnUnderline (i + 7);
table.setColumnJustification (0, Table::right); table.setColumnJustification (i + 0, Table::right);
table.setColumnJustification (1, Table::right); table.setColumnJustification (i + 1, Table::right);
table.setColumnJustification (2, Table::right); table.setColumnJustification (i + 2, Table::right);
table.setColumnJustification (3, Table::right); table.setColumnJustification (i + 3, Table::right);
table.setColumnJustification (4, Table::right); table.setColumnJustification (i + 4, Table::right);
table.setColumnJustification (5, Table::right); table.setColumnJustification (i + 5, Table::right);
table.setColumnJustification (6, Table::right); table.setColumnJustification (i + 6, Table::right);
table.setColumnJustification (7, Table::right); table.setColumnJustification (i + 7, Table::right);
}
int days = Date::daysInMonth (month, year); // Set number of days per month, months to render, and years to render.
int row = table.addRow (); std::vector<int> years;
for (int d = 1; d <= days; ++d) std::vector<int> months;
std::vector<int> daysInMonth;
int thisYear = firstYear;
int thisMonth = firstMonth;
for (int i = 0 ; i < monthsPerLine ; i++)
{ {
Date temp (month, d, year); if (thisMonth < 13)
int dow = temp.dayOfWeek (); {
years.push_back (thisYear);
}
else
{
thisMonth -= 12;
years.push_back (++thisYear);
}
months.push_back (thisMonth);
daysInMonth.push_back (Date::daysInMonth (thisMonth++, thisYear));
}
table.addCell (row, dow + 1, d); int row = table.addRow ();
// Loop through months to be added on this line.
for (int c = 0 ; c < monthsPerLine ; c++)
{
// Reset row counter for subsequent months
if (c != 0)
row = 0;
// Loop through days in month and add to table.
for (int d = 1; d <= daysInMonth.at (c); ++d)
{
Date temp (months.at (c), d, years.at (c));
int dow = temp.dayOfWeek ();
int thisCol = dow + 1 + (8 * c);
table.addCell (row, thisCol, d);
if (conf.get ("color", true) && if (conf.get ("color", true) &&
today.day () == d && today.day () == d &&
today.month () == month && today.month () == months.at (c) &&
today.year () == year) today.year () == years.at (c))
table.setCellFg (row, dow + 1, Text::cyan); table.setCellFg (row, thisCol, Text::cyan);
std::vector <T>::iterator it; std::vector <T>::iterator it;
for (it = all.begin (); it != all.end (); ++it) for (it = all.begin (); it != all.end (); ++it)
@ -1896,17 +1930,30 @@ std::string renderMonth (
if (conf.get ("color", true) && if (conf.get ("color", true) &&
due.day () == d && due.day () == d &&
due.month () == month && due.month () == months.at (c) &&
due.year () == year) due.year () == years.at (c))
{ {
table.setCellFg (row, dow + 1, Text::black); table.setCellFg (row, thisCol, Text::black);
table.setCellBg (row, dow + 1, due < today ? Text::on_red : Text::on_yellow); table.setCellBg (row, thisCol, due < today ? Text::on_red : Text::on_yellow);
} }
} }
if (dow == 6 && d < days) // Check for end of week, and...
if (dow == 6 && d < daysInMonth.at (c))
{
// ... Add a row if required, or...
if (c == 0)
{
row = table.addRow (); row = table.addRow ();
} }
// ... Reuse existing row.
else
{
row++;
}
}
}
}
return table.render (); return table.render ();
} }
@ -1943,19 +1990,42 @@ void handleReportCalendar (const TDB& tdb, T& task, Config& conf)
std::cout << std::endl; std::cout << std::endl;
std::string output; std::string output;
int monthsPerLine = (conf.get ("monthsperline", 1));
while (yFrom < yTo || (yFrom == yTo && mFrom <= mTo)) while (yFrom < yTo || (yFrom == yTo && mFrom <= mTo))
{ {
std::cout << Date::monthName (mFrom) int nextM = mFrom;
int nextY = yFrom;
// Print month headers (cheating on the width settings, yes)
for (int i = 0 ; i < monthsPerLine ; i++)
{
std::string month = Date::monthName (nextM);
std::cout << month
<< " " << " "
<< yFrom << std::setw(23 // one month's output width
- month.length ()// month name length
- 1)// spacer character
<< std::left
<< nextY;
if (++nextM > 12)
{
nextM = 1;
nextY++;
}
}
std::cout << std::endl
<< optionalBlankLine (conf) << optionalBlankLine (conf)
<< optionalBlankLine (conf) << renderMonths (mFrom, yFrom, today, pending, conf)
<< renderMonth (mFrom, yFrom, today, pending, conf)
<< std::endl; << std::endl;
if (++mFrom == 13) mFrom += monthsPerLine;
if (mFrom > 12)
{ {
mFrom = 1; mFrom -= 12;
++yFrom; ++yFrom;
} }
} }
@ -2265,7 +2335,9 @@ void handleReportStats (const TDB& tdb, T& task, Config& conf)
std::cout << "Task deleted every " << formatSeconds ((latest - earliest) / deletedT) << std::endl; std::cout << "Task deleted every " << formatSeconds ((latest - earliest) / deletedT) << std::endl;
if (pendingT || completedT) if (pendingT || completedT)
std::cout << "Average time pending " << formatSeconds ((int) ((daysPending / (pendingT + completedT)) * 86400)) << std::endl; std::cout << "Average time pending "
<< formatSeconds ((int) ((daysPending / (pendingT + completedT)) * 86400))
<< std::endl;
if (totalT) if (totalT)
{ {
@ -2821,4 +2893,3 @@ void nag (const TDB& tdb, T& task, Config& conf)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////