mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
CmdHistory: Code Cleanup
- Fixed formatting inconsistencies. - Added Lukas to AUTHORS.
This commit is contained in:
parent
91b73270c8
commit
00a4cbf906
3 changed files with 83 additions and 47 deletions
1
AUTHORS
1
AUTHORS
|
@ -137,6 +137,7 @@ The following submitted code, packages or analysis, and deserve special thanks:
|
|||
Jelle van der Waa
|
||||
Flavio Poletti
|
||||
Antonio Huete Jimenez
|
||||
Lukas Barth
|
||||
|
||||
Thanks to the following, who submitted detailed bug reports and excellent
|
||||
suggestions:
|
||||
|
|
|
@ -56,6 +56,7 @@ CmdHistoryBase<HistoryStrategy>::CmdHistoryBase ()
|
|||
_category = Command::Category::graphs;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class HistoryStrategy>
|
||||
void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
||||
{
|
||||
|
@ -116,10 +117,10 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
|||
unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
|
||||
unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine;
|
||||
|
||||
std::string bar = "";
|
||||
std::string bar;
|
||||
if (context.color ())
|
||||
{
|
||||
std::string aBar = "";
|
||||
std::string aBar;
|
||||
if (addedGroup[i.first])
|
||||
{
|
||||
aBar = format (addedGroup[i.first]);
|
||||
|
@ -127,7 +128,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
|||
aBar = ' ' + aBar;
|
||||
}
|
||||
|
||||
std::string cBar = "";
|
||||
std::string cBar;
|
||||
if (completedGroup[i.first])
|
||||
{
|
||||
cBar = format (completedGroup[i.first]);
|
||||
|
@ -135,7 +136,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
|||
cBar = ' ' + cBar;
|
||||
}
|
||||
|
||||
std::string dBar = "";
|
||||
std::string dBar;
|
||||
if (deletedGroup[i.first])
|
||||
{
|
||||
dBar = format (deletedGroup[i.first]);
|
||||
|
@ -151,9 +152,9 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::string aBar = ""; while (aBar.length () < addedBar) aBar += '+';
|
||||
std::string cBar = ""; while (cBar.length () < completedBar) cBar += 'X';
|
||||
std::string dBar = ""; while (dBar.length () < deletedBar) dBar += '-';
|
||||
std::string aBar; while (aBar.length () < addedBar) aBar += '+';
|
||||
std::string cBar; while (cBar.length () < completedBar) cBar += 'X';
|
||||
std::string dBar; while (dBar.length () < deletedBar) dBar += '-';
|
||||
|
||||
bar += std::string (leftOffset - aBar.length (), ' ');
|
||||
bar += aBar + cBar + dBar;
|
||||
|
@ -190,6 +191,7 @@ void CmdHistoryBase<HistoryStrategy>::outputGraphical (std::string &output)
|
|||
output = out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class HistoryStrategy>
|
||||
void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output)
|
||||
{
|
||||
|
@ -288,6 +290,7 @@ void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output)
|
|||
output = out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template<class HistoryStrategy>
|
||||
int CmdHistoryBase<HistoryStrategy>::execute (std::string& output)
|
||||
{
|
||||
|
@ -353,3 +356,5 @@ template class CmdHistoryBase<MonthlyHistoryStrategy>;
|
|||
template class CmdHistoryBase<AnnualHistoryStrategy>;
|
||||
template class CmdHistoryBase<MonthlyGHistoryStrategy>;
|
||||
template class CmdHistoryBase<AnnualGHistoryStrategy>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -47,23 +47,31 @@ private:
|
|||
std::map <time_t, int> deletedGroup; // Deletions by timeinterval
|
||||
int rc;
|
||||
|
||||
void outputTabular(std::string&);
|
||||
void outputGraphical(std::string&);
|
||||
void outputTabular (std::string&);
|
||||
void outputGraphical (std::string&);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class MonthlyHistoryStrategy {
|
||||
class MonthlyHistoryStrategy
|
||||
{
|
||||
public:
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
static Datetime getRelevantDate (const Datetime & dt)
|
||||
{
|
||||
return dt.startOfMonth ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
static void setupTableDates (Table & view)
|
||||
{
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
view.add (STRING_CMD_HISTORY_MONTH);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
static void insertRowDate (
|
||||
Table& view,
|
||||
int row,
|
||||
time_t rowTime,
|
||||
time_t lastTime)
|
||||
{
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
@ -76,33 +84,41 @@ public:
|
|||
{
|
||||
view.set (row, 0, y);
|
||||
}
|
||||
view.set (row, 1, Datetime::monthName(m));
|
||||
|
||||
view.set (row, 1, Datetime::monthName (m));
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "history.monthly";
|
||||
static constexpr const char * usage = "task <filter> history.monthly";
|
||||
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_M;
|
||||
static constexpr const char* keyword = "history.monthly";
|
||||
static constexpr const char* usage = "task <filter> history.monthly";
|
||||
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_M;
|
||||
static constexpr unsigned int dateFieldCount = 2;
|
||||
static constexpr bool graphical = false;
|
||||
static constexpr bool graphical = false;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class MonthlyGHistoryStrategy {
|
||||
class MonthlyGHistoryStrategy
|
||||
{
|
||||
public:
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
static Datetime getRelevantDate (const Datetime & dt)
|
||||
{
|
||||
return dt.startOfMonth ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
static void setupTableDates (Table & view)
|
||||
{
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
view.add (STRING_CMD_HISTORY_MONTH);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
static void insertRowDate (
|
||||
Table& view,
|
||||
int row,
|
||||
time_t rowTime,
|
||||
time_t lastTime)
|
||||
{
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
@ -115,32 +131,40 @@ public:
|
|||
{
|
||||
view.set (row, 0, y);
|
||||
}
|
||||
view.set (row, 1, Datetime::monthName(m));
|
||||
|
||||
view.set (row, 1, Datetime::monthName (m));
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "ghistory.monthly";
|
||||
static constexpr const char * usage = "task <filter> ghistory.monthly";
|
||||
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_M;
|
||||
static constexpr const char* keyword = "ghistory.monthly";
|
||||
static constexpr const char* usage = "task <filter> ghistory.monthly";
|
||||
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_M;
|
||||
static constexpr unsigned int dateFieldCount = 2;
|
||||
static constexpr bool graphical = true;
|
||||
static constexpr bool graphical = true;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class AnnualHistoryStrategy {
|
||||
class AnnualHistoryStrategy
|
||||
{
|
||||
public:
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
static Datetime getRelevantDate (const Datetime & dt)
|
||||
{
|
||||
return dt.startOfYear ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
static void setupTableDates (Table & view)
|
||||
{
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
static void insertRowDate (
|
||||
Table& view,
|
||||
int row,
|
||||
time_t rowTime,
|
||||
time_t lastTime)
|
||||
{
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
@ -155,29 +179,36 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "history.annual";
|
||||
static constexpr const char * usage = "task <filter> history.annual";
|
||||
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_A;
|
||||
static constexpr const char* keyword = "history.annual";
|
||||
static constexpr const char* usage = "task <filter> history.annual";
|
||||
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_A;
|
||||
static constexpr unsigned int dateFieldCount = 1;
|
||||
static constexpr bool graphical = false;
|
||||
static constexpr bool graphical = false;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class AnnualGHistoryStrategy {
|
||||
class AnnualGHistoryStrategy
|
||||
{
|
||||
public:
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
static Datetime getRelevantDate (const Datetime & dt)
|
||||
{
|
||||
return dt.startOfYear ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
static void setupTableDates (Table & view)
|
||||
{
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
static void insertRowDate (
|
||||
Table& view,
|
||||
int row,
|
||||
time_t rowTime,
|
||||
time_t lastTime)
|
||||
{
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
@ -192,14 +223,13 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "ghistory.annual";
|
||||
static constexpr const char * usage = "task <filter> ghistory.annual";
|
||||
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_A;
|
||||
static constexpr const char* keyword = "ghistory.annual";
|
||||
static constexpr const char* usage = "task <filter> ghistory.annual";
|
||||
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_A;
|
||||
static constexpr unsigned int dateFieldCount = 1;
|
||||
static constexpr bool graphical = true;
|
||||
static constexpr bool graphical = true;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue