From f2629aca7bdfd280e8e7268952e9016c56b2294e Mon Sep 17 00:00:00 2001 From: Will Song Date: Fri, 29 May 2015 20:23:09 -0500 Subject: updated statusbar to use strftime formats --- src/ui/statusbar.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/ui/statusbar.c') diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 581e63df..c388a874 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -129,10 +129,13 @@ status_bar_resize(void) if (message) { char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "minutes") == 0) { - mvwprintw(status_bar, 0, 10, message); - } else if (g_strcmp0(time_pref, "seconds") == 0) { - mvwprintw(status_bar, 0, 13, message); + gchar *date_fmt = g_date_time_format(last_time, time_pref); + assert(date_fmt != NULL); + size_t len = strlen(date_fmt); + if (g_strcmp0(time_pref, "") != 0) { + /* 01234567890123456 + * [HH:MM] message */ + mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); } @@ -303,10 +306,11 @@ status_bar_print_message(const char * const msg) message = strdup(msg); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "minutes") == 0) { - mvwprintw(status_bar, 0, 10, message); - } else if (g_strcmp0(time_pref, "seconds") == 0) { - mvwprintw(status_bar, 0, 13, message); + gchar *date_fmt = g_date_time_format(last_time, time_pref); + assert(date_fmt != NULL); + size_t len = strlen(date_fmt); + if (g_strcmp0(time_pref, "") != 0) { + mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); } @@ -436,26 +440,16 @@ _status_bar_draw(void) int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "minutes") == 0) { - gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); - assert(date_fmt != NULL); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 1, '['); - wattroff(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, 2, date_fmt); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 7, ']'); - wattroff(status_bar, bracket_attrs); - g_free(date_fmt); - } else if (g_strcmp0(time_pref, "seconds") == 0) { - gchar *date_fmt = g_date_time_format(last_time, "%H:%M:%S"); + if (g_strcmp0(time_pref, "") != 0) { + gchar *date_fmt = g_date_time_format(last_time, time_pref); assert(date_fmt != NULL); + size_t len = strlen(date_fmt); wattron(status_bar, bracket_attrs); mvwaddch(status_bar, 0, 1, '['); wattroff(status_bar, bracket_attrs); mvwprintw(status_bar, 0, 2, date_fmt); wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 10, ']'); + mvwaddch(status_bar, 0, 2 + len, ']'); wattroff(status_bar, bracket_attrs); g_free(date_fmt); } -- cgit 1.4.1-2-gfad0