diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit a72fc62a9839d509696a3d76c9a71a422b29ade5
parent 8b7e56873c09fd35980c991fab6f78ff08a817f6
Author: Ryan Bahneman <rbahneman@apple.com>
Date:   Tue, 22 Nov 2016 11:58:34 -0800

Underlining the current date

Diffstat:
Mdiary.c | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/diary.c b/diary.c @@ -39,14 +39,28 @@ void draw_calendar(WINDOW* number_pad, WINDOW* month_pad) { char month[10]; while (mktime(&i) <= mktime(&cal_end)) { + bool is_today = ((cur_date.tm_year == i.tm_year) && (cur_date.tm_yday == i.tm_yday)); getyx(number_pad, cy, cx); + if (is_today) { + wattron(number_pad, A_UNDERLINE); + } mvwprintw(number_pad, cy, cx, "%2i", i.tm_mday); + if (is_today) { + wattroff(number_pad, A_UNDERLINE); + } waddch(number_pad, ' '); if (i.tm_mday == 1) { + bool is_month = ((cur_date.tm_year == i.tm_year) && (cur_date.tm_mon == i.tm_mon)); strftime(month, sizeof month, "%b", &i); getyx(number_pad, cy, cx); - mvwprintw(month_pad, cy, 0, "%s ", month); + if (is_month) { + wattron(month_pad, A_UNDERLINE); + } + mvwprintw(month_pad, cy, 0, "%s", month); + if (is_month) { + wattroff(month_pad, A_UNDERLINE); + } } i.tm_mday++; @@ -124,14 +138,22 @@ bool go_to(WINDOW* calendar, WINDOW* month_sidebar, time_t date, int* cur_pad_po localtime_r(&date, &curs_date); getyx(calendar, cy, cx); - mvwchgat(calendar, cy , 0 , -1, A_NORMAL, 0, NULL); - mvwchgat(calendar, diff_weeks, diff_wdays * 3, 2, A_STANDOUT, 0, NULL); + + // Remove the STANDOUT attribute from the day we are leaving + chtype current_attrs = mvwinch(calendar, cy, cx) & A_ATTRIBUTES; + current_attrs &= ~A_STANDOUT; + mvwchgat(calendar, cy , cx , 2, current_attrs, 0, NULL); + + // Add the STANDOUT attribute to the day we are entering + chtype new_attrs = mvwinch(calendar, diff_weeks, diff_wdays * 3) & A_ATTRIBUTES; + new_attrs |= A_STANDOUT; + mvwchgat(calendar, diff_weeks, diff_wdays * 3, 2, new_attrs, 0, NULL); if (diff_weeks < *cur_pad_pos) *cur_pad_pos = diff_weeks; if (diff_weeks > *cur_pad_pos + LINES - 2) *cur_pad_pos = diff_weeks - LINES + 2; - prefresh(month_sidebar, *cur_pad_pos, 0, 1, 0, LINES - 1, CAL_MONTH_WIDTH); + prefresh(month_sidebar, *cur_pad_pos, 0, 1, 0, LINES - 1, CAL_MONTH_WIDTH); prefresh(calendar, *cur_pad_pos, 0, 1, CAL_MONTH_WIDTH, LINES - 1, CAL_MONTH_WIDTH + CAL_DAY_WIDTH); return true;