From d56cc7acfe85119b70f7aac8dfd13ba41ec119e3 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Sat, 19 Aug 2017 10:23:52 +0200 Subject: Make heading in appointments panel configurable Add a new configuration variable format.dayheading to set the format of the date displayed at the top of the event and appointment list. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/ui-day.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index 24717dc..ab588fd 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -909,6 +909,17 @@ void ui_day_sel_move(int delta) listbox_sel_move(&lb_apt, delta); } +static char *fmt_day_heading(time_t date) +{ + struct tm tm; + struct string s; + + localtime_r(&date, &tm); + string_printf(&s, "%s ", ui_calendar_get_pom(date)); + string_catftime(&s, conf.day_heading, &tm); + return string_buf(&s); +} + /* Display appointments in the corresponding panel. */ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) { @@ -918,20 +929,18 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) int width = lb_apt.sw.w - 2; hilt = hilt && (wins_slctd() == APP); - if (item->type == EVNT || item->type == RECUR_EVNT) { day_display_item(item, win, !hilt, width - 1, y, 1); } else if (item->type == APPT || item->type == RECUR_APPT) { day_display_item_date(item, win, !hilt, date, y, 1); day_display_item(item, win, !hilt, width - 1, y + 1, 1); } else if (item->type == DAY_HEADING) { - unsigned x = width - (strlen(_(monthnames[slctd_date.mm - 1])) + 15); + char *buf = fmt_day_heading(date); + utf8_chop(buf, width); custom_apply_attr(win, ATTR_HIGHEST); - mvwprintw(win, y, x, "%s %s %02d, %04d", - ui_calendar_get_pom(date), - _(monthnames[slctd_date.mm - 1]), slctd_date.dd, - slctd_date.yyyy); + mvwprintw(win, y, width - utf8_strwidth(buf) - 1, "%s", buf); custom_remove_attr(win, ATTR_HIGHEST); + mem_free(buf); } else if (item->type == DAY_SEPARATOR) { wmove(win, y, 0); whline(win, 0, width); -- cgit v1.2.3-54-g00ecf