diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/console.c | 6 | ||||
-rw-r--r-- | src/ui/inputwin.c | 29 | ||||
-rw-r--r-- | src/ui/statusbar.c | 40 | ||||
-rw-r--r-- | src/ui/window.c | 38 |
4 files changed, 46 insertions, 67 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index 226619e9..8bf873a5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -954,12 +954,10 @@ void cons_time_setting(void) { char *pref_time = prefs_get_string(PREF_TIME); - if (g_strcmp0(pref_time, "minutes") == 0) - cons_show("Time (/time) : minutes"); - else if (g_strcmp0(pref_time, "off") == 0) + if (g_strcmp0(pref_time, "off") == 0) cons_show("Time (/time) : OFF"); else - cons_show("Time (/time) : seconds"); + cons_show("Time (/time) : %s", pref_time); prefs_free_string(pref_time); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 2c42a628..1ea46984 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -71,6 +71,7 @@ static WINDOW *inp_win; static int pad_start = 0; static struct timeval p_rl_timeout; +/* Timeout in ms. Shows how long select() may block. */ static gint inp_timeout = 0; static gint no_input_count = 0; @@ -115,14 +116,6 @@ create_input_window(void) #else ESCDELAY = 25; #endif - if (inp_timeout == 1000) { - p_rl_timeout.tv_sec = 1; - p_rl_timeout.tv_usec = 0; - } else { - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; - } - rl_readline_name = "profanity"; rl_getc_function = _inp_rl_getc; rl_startup_hook = _inp_rl_startup_hook; @@ -141,13 +134,17 @@ inp_readline(void) { free(inp_line); inp_line = NULL; + p_rl_timeout.tv_sec = inp_timeout / 1000; + p_rl_timeout.tv_usec = inp_timeout % 1000 * 1000; FD_ZERO(&fds); FD_SET(fileno(rl_instream), &fds); errno = 0; r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); if (r < 0) { - char *err_msg = strerror(errno); - log_error("Readline failed: %s", err_msg); + if (errno != EINTR) { + char *err_msg = strerror(errno); + log_error("Readline failed: %s", err_msg); + } return NULL; } @@ -162,21 +159,15 @@ inp_readline(void) } ui_reset_idle_time(); - _inp_write(rl_line_buffer, rl_point); + if (!get_password) { + _inp_write(rl_line_buffer, rl_point); + } inp_nonblocking(TRUE); } else { inp_nonblocking(FALSE); prof_handle_idle(); } - if (inp_timeout == 1000) { - p_rl_timeout.tv_sec = 1; - p_rl_timeout.tv_usec = 0; - } else { - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; - } - if (inp_line) { return strdup(inp_line); } else { diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 97321bca..5541f648 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -129,10 +129,14 @@ 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); + g_free(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); } @@ -304,10 +308,12 @@ 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); + g_free(date_fmt); + if (g_strcmp0(time_pref, "") != 0) { + mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); } @@ -438,26 +444,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); } diff --git a/src/ui/window.c b/src/ui/window.c index 9db4f854..c008e44d 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -36,6 +36,7 @@ #include <stdlib.h> #include <string.h> +#include <time.h> #include <assert.h> #include <wchar.h> @@ -60,7 +61,7 @@ static void _win_print(ProfWin *window, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt); -static void _win_print_wrapped(WINDOW *win, const char * const message); +static void _win_print_wrapped(WINDOW *win, const char * const message, size_t indent); int win_roster_cols(void) @@ -1016,18 +1017,20 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, gboolean me_message = FALSE; int offset = 0; int colour = theme_attrs(THEME_ME); + size_t indent = 0; - if ((flags & NO_DATE) == 0) { - gchar *date_fmt = NULL; - char *time_pref = prefs_get_string(PREF_TIME); - if (g_strcmp0(time_pref, "minutes") == 0) { - date_fmt = g_date_time_format(time, "%H:%M"); - } else if (g_strcmp0(time_pref, "seconds") == 0) { - date_fmt = g_date_time_format(time, "%H:%M:%S"); - } - free(time_pref); + gchar *date_fmt = NULL; + char *time_pref = prefs_get_string(PREF_TIME); + date_fmt = g_date_time_format(time, time_pref); + free(time_pref); + assert(date_fmt != NULL); + + if(strlen(date_fmt) != 0){ + indent = 3 + strlen(date_fmt); + } - if (date_fmt) { + if ((flags & NO_DATE) == 0) { + if (date_fmt && strlen(date_fmt)) { if ((flags & NO_COLOUR_DATE) == 0) { wattron(window->layout->win, theme_attrs(THEME_TIME)); } @@ -1072,7 +1075,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, } if (prefs_get_boolean(PREF_WRAP)) { - _win_print_wrapped(window->layout->win, message+offset); + _win_print_wrapped(window->layout->win, message+offset, indent); } else { wprintw(window->layout->win, "%s", message+offset); } @@ -1102,20 +1105,11 @@ _win_indent(WINDOW *win, int size) } static void -_win_print_wrapped(WINDOW *win, const char * const message) +_win_print_wrapped(WINDOW *win, const char * const message, size_t indent) { int wordi = 0; char *word = malloc(strlen(message) + 1); - char *time_pref = prefs_get_string(PREF_TIME); - int indent = 0; - if (g_strcmp0(time_pref, "minutes") == 0) { - indent = 8; - } else if (g_strcmp0(time_pref, "seconds") == 0) { - indent = 11; - } - free(time_pref); - gchar *curr_ch = g_utf8_offset_to_pointer(message, 0); while (*curr_ch != '\0') { |