commit b514f4247914944e68d86e74cfa78491a21f1ff1
parent bf347f2b1d178483b26132b64bf031dfa1e39fa8
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 16 Mar 2025 22:18:23 +0100
replace silly span with cool daily recurrence
Diffstat:
M | scal.c | | | 44 | ++++++++++++++++++-------------------------- |
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/scal.c b/scal.c
@@ -14,7 +14,7 @@
#define ctrl(x) ((x) & 0x1f)
-typedef enum {NO, YEARLY, MONTHLY, WEEKLY} Recurring;
+typedef enum {NO, YEARLY, MONTHLY, WEEKLY, DAILY} Recurring;
typedef struct
{
@@ -195,12 +195,12 @@ print_month(const int monthadd, int *y)
today = same_day(&otm, &curtm, 0);
notecol = get_relevant_recur(&otm);
- if ((wnote = notecol != -1))
- color = get_note_view_col(notecol);
if (today)
wattron(wwin, A_UNDERLINE);
- if (wnote)
+ if (wnote = notecol != -1) {
+ color = get_note_view_col(notecol);
wattron(wwin, COLOR_PAIR(color));
+ }
if (monthadd == 0 && highlight == i) {
wattron(wwin, A_REVERSE);
mvwprintw(wwin, *y, x, "%d", otm.tm_mday);
@@ -335,8 +335,7 @@ combo_make(int key)
void
add_note(struct tm *tm) {
size_t len;
- int duration = 1;
- char answer[DESCLEN+20], buf[DESCLEN], rec[2], time[6], date[11], prefill[11], span[2], dur[3];
+ char answer[DESCLEN+20], buf[DESCLEN], rec[2], time[6], date[11], prefill[11], span[2];
char end[11] = "2999-12-31\0";
if (tm != NULL)
@@ -345,22 +344,14 @@ add_note(struct tm *tm) {
tm->tm_mon+1,
tm->tm_mday);
- if (prompt_answer(rec, 1, "Recurring? (0=NO;1=YEARLY;2=MONTHLY;3=WEEKLY)", "3", "0"))
+ if (prompt_answer(rec, 1, "Recurring? (0=NO;1=YEARLY;2=MONTHLY;3=WEEKLY;4=DAILY)", "4", "0"))
return;
if (prompt_answer(date, 10, "Date?", "2999-19-39", prefill))
return;
if (prompt_answer(time, 5, "Time?", "29:59", NULL))
return;
- if (rec[0] == '0') {
- if (prompt_answer(span, 1, "Span? (0=NO;1=YES)", "1", "0"))
- return;
- if (span[0] == '1') {
- if (prompt_answer(dur, 2, "Span Duration ? (in days)", "99", "01"))
- return;
- duration = atoi(dur);
- }
- } else {
+ if (rec[0] != '0') {
if (prompt_answer(span, 1, "Set end date? (0=NO;1=YES)", "1", "0"))
return;
if (span[0] == '1') {
@@ -377,16 +368,13 @@ add_note(struct tm *tm) {
len = strlen(answer);
if (len > sizeof(rec) + sizeof(date) + sizeof(end) + sizeof(time)) {
- for (int i = 1; i <= duration; i++) {
- notes = (Note**) realloc(notes, (sizeof(Note*) * (note_count + 1)));
- if (notes == NULL)
- fatal("Fatal: failed to reallocate bytes for notes.\n");
+ notes = (Note**) realloc(notes, (sizeof(Note*) * (note_count + 1)));
+ if (notes == NULL)
+ fatal("Fatal: failed to reallocate bytes for notes.\n");
- notes[note_count] = get_note(answer, len);
- notes[note_count]->time.tm_mday+=i-1;
- timegm(¬es[note_count]->time);
- note_count++;
- }
+ notes[note_count] = get_note(answer, len);
+ timegm(¬es[note_count]->time);
+ note_count++;
write_notes();
}
}
@@ -577,7 +565,7 @@ get_relevant_recur(struct tm *tm)
for (int i = 0; i < note_count; i++) {
if (is_relevant(notes[i], tm))
- relevant = MIN(notes[i]->recurring, relevant == -1 ? WEEKLY : relevant);
+ relevant = MIN(notes[i]->recurring, relevant == -1 ? 4 : relevant);
}
return relevant;
@@ -741,6 +729,8 @@ int
get_note_view_col(Recurring recurring)
{
switch (recurring) {
+ case DAILY:
+ return DAILY_VIEW_COLOR;
case WEEKLY:
return WEEKLY_VIEW_COLOR;
case MONTHLY:
@@ -799,6 +789,8 @@ same_day(struct tm *a, struct tm *b, Recurring recurring)
timegm(b);
switch (recurring) {
+ case DAILY:
+ return a->tm_yday <= b->tm_yday;
case WEEKLY:
return a->tm_wday == b->tm_wday;
case MONTHLY: