commit 68fbc6019ce5ee9aa051a36f8f452fa81a03bf65
parent 426bda389a208ddbbd2909e395be6eeae2c65cd7
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 16 Mar 2025 18:13:23 +0100
differentiate view colour on recurring
Diffstat:
M | config.def.h | | | 4 | ++-- |
M | scal.c | | | 62 | ++++++++++++++++++++++++++++++++++++-------------------------- |
2 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -30,9 +30,9 @@
#define MONTH_TITLE_COLOR COLOR_MAGENTA
#define CURDAY_COLOR COLOR_GREEN
#define NOTED_COLOR COLOR_RED
-#define WEEKLY_VIEW_COLOR COLOR_WHITE
+#define WEEKLY_VIEW_COLOR COLOR_BLUE
#define MONTHLY_VIEW_COLOR COLOR_YELLOW
-#define YEARLY_VIEW_COLOR COLOR_RED
+#define YEARLY_VIEW_COLOR COLOR_MAGENTA
#define PROMPT_COLOR COLOR_RED
#endif
diff --git a/scal.c b/scal.c
@@ -30,6 +30,7 @@ static void print_words(void);
static void write_notes(void);
static Note ** get_notes(void);
static Note * get_note(char *line_buf, ssize_t line_size);
+static Recurring get_relevant_recur(struct tm *tm);
static void print_view(void);
static void print_month(const int monthadd, int *y);
static void combo_key(int keypress);
@@ -41,7 +42,6 @@ static void rm_note(struct tm *tm);
static int prompt_answer(char *buf, size_t size, const char *question, const char *mask, char *prefill);
static int get_curnotes(void);
static int get_note_view_col(Recurring recurring);
-static int has_note(struct tm *tm);
static int get_days(const struct tm *tm);
static int days_between(struct tm *tsa, struct tm *tsb);
static int same_day(struct tm *a, struct tm *b, Recurring recurring);
@@ -167,7 +167,8 @@ print_words(void)
void
print_month(const int monthadd, int *y)
{
- int wcount, today, wnote, sindex, x = 0;
+ int wcount, today, wnote, sindex, color, x = 0;
+ Recurring notecol;
struct tm otm = highltm;
if (monthadd >= 0)
@@ -190,12 +191,14 @@ print_month(const int monthadd, int *y)
for (size_t i = 0; i < wcount; ++i) {
otm.tm_mday=i+1;
today = same_day(&otm, &curtm, 0);
- wnote = has_note(&otm);
+ notecol = get_relevant_recur(&otm);
+ if ((wnote = notecol != -1))
+ color = get_note_view_col(notecol);
if (today)
wattron(wwin, COLOR_PAIR(CURDAY_COLOR));
if (wnote)
- wattron(wwin, COLOR_PAIR(NOTED_COLOR));
+ wattron(wwin, COLOR_PAIR(color));
if (monthadd == 0 && highlight == i) {
wattron(wwin, A_REVERSE);
mvwprintw(wwin, *y, x, "%d", otm.tm_mday);
@@ -205,7 +208,7 @@ print_month(const int monthadd, int *y)
if (today)
wattroff(wwin, COLOR_PAIR(CURDAY_COLOR));
if (wnote)
- wattroff(wwin, COLOR_PAIR(NOTED_COLOR));
+ wattroff(wwin, COLOR_PAIR(color));
x+=3;
if (x % DAY_COLUMN_SIZE == 0 && i != wcount-1) {
(*y)++;
@@ -525,8 +528,7 @@ get_note(char *line_buf, ssize_t line_size)
if (note->description == NULL)
fatal("Fatal: failed to allocate bytes for note.\n");
- sscanf(line_buf,
- "%d|%[^|]|%[^\n]",
+ sscanf(line_buf, "%d|%[^|]|%[^\n]",
¬e->recurring,
timestr,
note->description);
@@ -546,6 +548,18 @@ get_note(char *line_buf, ssize_t line_size)
return note;
}
+Recurring
+get_relevant_recur(struct tm *tm)
+{
+ Recurring relevant = -1;
+
+ for (int i = 0; i < note_count; i++)
+ if (same_day(&(notes[i]->time), tm, notes[i]->recurring))
+ relevant = MIN(notes[i]->recurring, relevant == -1 ? WEEKLY : relevant);
+
+ return relevant;
+}
+
void
print_view(void)
{
@@ -678,8 +692,6 @@ prompt_answer(char *buf, size_t size, const char *question, const char *mask, ch
int
get_curnotes(void)
{
- int entered = 0;
-
if (curnote_count > 0) {
curnote_count = 0;
free(curnotes);
@@ -698,9 +710,7 @@ get_curnotes(void)
fatal("Fatal: failed to reallocate bytes for notes.\n");
curnotes[curnote_count] = notes[i];
curnote_count++;
- entered = 1;
- } else if (entered)
- break;
+ }
}
}
@@ -714,22 +724,14 @@ get_note_view_col(Recurring recurring)
return MONTHLY_VIEW_COLOR;
case YEARLY:
return YEARLY_VIEW_COLOR;
+ case NO:
+ return NOTED_COLOR;
default:
return -1;
}
}
int
-has_note(struct tm *tm)
-{
- for (int i = 0; i < note_count; i++) {
- if (same_day(&(notes[i]->time), tm, notes[i]->recurring))
- return 1;
- }
- return 0;
-}
-
-int
get_days(const struct tm *tm)
{
struct tm start = *tm, end = *tm;
@@ -759,9 +761,18 @@ same_day(struct tm *a, struct tm *b, Recurring recurring)
mktime(a);
mktime(b);
- return ((recurring == WEEKLY && a->tm_wday == b->tm_wday) || a->tm_mday == b->tm_mday )
- && (recurring >= MONTHLY || a->tm_mon == b->tm_mon)
- && (recurring >= YEARLY || a->tm_year == b->tm_year);
+ switch (recurring) {
+ case WEEKLY:
+ return a->tm_wday == b->tm_wday;
+ case MONTHLY:
+ return a->tm_mday == b->tm_mday;
+ case YEARLY:
+ return a->tm_mday == b->tm_mday && a->tm_mon == b->tm_mon;
+ case NO:
+ return a->tm_yday == b->tm_yday && a->tm_year == b->tm_year;
+ default:
+ return 0;
+ }
}
int
@@ -787,7 +798,6 @@ compare_note(const void *a, const void *b)
return ma->time.tm_min > mb->time.tm_min;
return 0;
- //return difftime(mktime(&ma->time), mktime(&mb->time));
}
void