From 3d61966831da3944714273571ca87fe46906003f Mon Sep 17 00:00:00 2001 From: sebu06 Date: Sun, 18 Jul 2021 19:03:26 +0200 Subject: [PATCH] Added coloring of dates with scheduled tasks Color can be changed using color.calendar.scheduled --- ChangeLog | 2 ++ src/Context.cpp | 1 + src/commands/CmdCalendar.cpp | 61 +++++++++++++++++++++++------------- src/commands/CmdShow.cpp | 1 + 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7932e746a..fdc35f036 100644 --- a/ChangeLog +++ b/ChangeLog @@ -77,6 +77,8 @@ Thanks to Scott Mcdermott - TW #1824 Fixed countdown formatting Thanks to Sebastian Uharek +- #2208 Feature: added coloring of dates with scheduled tasks to calendar + Thanks to Sebastian Uharek ------ current release --------------------------- diff --git a/src/Context.cpp b/src/Context.cpp index d6e58463e..fc7cfe130 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -227,6 +227,7 @@ std::string configurationDefaults = "color.calendar.due.today=color15 on color1\n" "color.calendar.due=color0 on color1\n" "color.calendar.holiday=color0 on color11\n" + "color.calendar.scheduled=rgb013 on color15\n" "color.calendar.overdue=color0 on color9\n" "color.calendar.today=color15 on rgb013\n" "color.calendar.weekend=on color235\n" diff --git a/src/commands/CmdCalendar.cpp b/src/commands/CmdCalendar.cpp index f068fb4fc..794200bce 100644 --- a/src/commands/CmdCalendar.cpp +++ b/src/commands/CmdCalendar.cpp @@ -290,6 +290,7 @@ int CmdCalendar::execute (std::string& output) Color color_overdue (config.get ("color.calendar.overdue")); Color color_weekend (config.get ("color.calendar.weekend")); Color color_holiday (config.get ("color.calendar.holiday")); + Color color_scheduled (config.get ("color.calendar.scheduled")); Color color_weeknumber (config.get ("color.calendar.weeknumber")); if (Context::getContext ().color () && config.getBoolean ("calendar.legend")) @@ -307,6 +308,8 @@ int CmdCalendar::execute (std::string& output) << color_duetoday.colorize ("due-today") << ", " << color_overdue.colorize ("overdue") + << ", " + << color_scheduled.colorize ("scheduled") << ", "; // If colorizing holidays, print legend @@ -528,6 +531,7 @@ std::string CmdCalendar::renderMonths ( Color color_overdue (config.get ("color.calendar.overdue")); Color color_weekend (config.get ("color.calendar.weekend")); Color color_holiday (config.get ("color.calendar.holiday")); + Color color_scheduled (config.get ("color.calendar.scheduled")); Color color_weeknumber (config.get ("color.calendar.weeknumber")); // Loop through months to be added on this line. @@ -573,7 +577,7 @@ std::string CmdCalendar::renderMonths ( if (config.get ("calendar.holidays") != "none") { auto dateFormat = config.get ("dateformat.holiday"); - for (auto& hol : config) + for (auto& hol : config) { if (hol.first.substr (0, 8) == "holiday.") { @@ -603,40 +607,55 @@ std::string CmdCalendar::renderMonths ( if (today.sameDay (date)) cellColor.blend (color_today); - // colorize due tasks + // colorize due and scheduled tasks if (config.get ("calendar.details") != "none") { config.set ("due", 0); + config.set ("scheduled", 0); + // if a date has a task that is due on that day, the due color + // takes precedence over the scheduled color + bool coloredWithDue = false; for (auto& task : all) { auto status = task.getStatus (); if ((status == Task::pending || status == Task::waiting ) && - !task.hasTag ("nocal") && - task.has ("due")) + !task.hasTag ("nocal")) { - std::string due = task.get ("due"); - Datetime duedmy (strtol (due.c_str(), nullptr, 10)); + if(task.has("scheduled") && !coloredWithDue) { + std::string scheduled = task.get ("scheduled"); + Datetime scheduleddmy (strtol (scheduled.c_str(), nullptr, 10)); - if (duedmy.sameDay (date)) - { - switch (task.getDateState ("due")) + if (scheduleddmy.sameDay (date)) { - case Task::dateNotDue: - break; + cellColor.blend(color_scheduled); + } + } + if(task.has("due")) { + std::string due = task.get ("due"); + Datetime duedmy (strtol (due.c_str(), nullptr, 10)); - case Task::dateAfterToday: - cellColor.blend (color_due); - break; + if (duedmy.sameDay (date)) + { + coloredWithDue = true; + switch (task.getDateState ("due")) + { + case Task::dateNotDue: + break; - case Task::dateLaterToday: - cellColor.blend (color_duetoday); - break; + case Task::dateAfterToday: + cellColor.blend (color_due); + break; - case Task::dateEarlierToday: - case Task::dateBeforeToday: - cellColor.blend (color_overdue); - break; + case Task::dateLaterToday: + cellColor.blend (color_duetoday); + break; + + case Task::dateEarlierToday: + case Task::dateBeforeToday: + cellColor.blend (color_overdue); + break; + } } } } diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index c1b6b77fb..ae5b88816 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -98,6 +98,7 @@ int CmdShow::execute (std::string& output) " color.calendar.due" " color.calendar.due.today" " color.calendar.holiday" + " color.calendar.scheduled" " color.calendar.overdue" " color.calendar.today" " color.calendar.weekend"