diff options
author | Will Song <incertia9474@gmail.com> | 2015-05-29 20:23:09 -0500 |
---|---|---|
committer | Will Song <incertia9474@gmail.com> | 2015-05-29 20:23:09 -0500 |
commit | f2629aca7bdfd280e8e7268952e9016c56b2294e (patch) | |
tree | 171595bbdf85559dc9a06a7640e154fa91dba750 /src | |
parent | 9463c6719036957c8468e1363a48afbfe751fd3e (diff) | |
download | profani-tty-f2629aca7bdfd280e8e7268952e9016c56b2294e.tar.gz |
updated statusbar to use strftime formats
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/statusbar.c | 38 |
1 files changed, 16 insertions, 22 deletions
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); } |