diff options
-rw-r--r-- | src/profanity.c | 13 | ||||
-rw-r--r-- | src/ui/core.c | 25 | ||||
-rw-r--r-- | src/ui/ui.h | 2 | ||||
-rw-r--r-- | tests/ui/stub_ui.c | 4 |
4 files changed, 27 insertions, 17 deletions
diff --git a/src/profanity.c b/src/profanity.c index 562e10b4..d7613396 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -79,17 +79,15 @@ prof_run(const int disable_tls, char *log_level, char *account_name) _connect_default(account_name); ui_update(); - char inp[INP_WIN_MAX]; - gboolean read_input = TRUE; + char *line = NULL; gboolean cmd_result = TRUE; log_info("Starting main event loop"); - while(cmd_result == TRUE) { - read_input = TRUE; - while(read_input) { + while(cmd_result) { + while(!line) { _check_autoaway(); - read_input = ui_get_char(inp); + line = ui_readline(); #ifdef HAVE_LIBOTR otr_poll(); #endif @@ -97,8 +95,9 @@ prof_run(const int disable_tls, char *log_level, char *account_name) jabber_process_events(); ui_update(); } - cmd_result = cmd_process_input(inp); + cmd_result = cmd_process_input(line); ui_input_clear(); + line = NULL; } } diff --git a/src/ui/core.c b/src/ui/core.c index 8b89b12e..f1a563d7 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -73,6 +73,8 @@ #include "xmpp/xmpp.h" static char *win_title; + +static char input[INP_WIN_MAX]; static int inp_size; #ifdef HAVE_LIBXSS @@ -176,14 +178,24 @@ ui_close(void) endwin(); } -gboolean -ui_get_char(char *input) +char* +ui_readline(void) { int result = 0; + gboolean return_line = FALSE; + wint_t ch = inp_get_char(input, &inp_size, &result); + if (ch == '\n') { + input[inp_size++] = '\0'; + inp_size = 0; + return_line = TRUE; + } + _win_handle_switch(ch); + ProfWin *current = wins_get_current(); win_handle_page(current, ch, result); + if (ch == KEY_RESIZE) { ui_resize(); } @@ -195,12 +207,11 @@ ui_get_char(char *input) ui_input_nonblocking(FALSE); } - if (ch == '\n') { - input[inp_size++] = '\0'; - inp_size = 0; + if (return_line) { + return input; + } else { + return NULL; } - - return (ch != '\n'); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 8141ed2a..be6d2fd0 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -229,7 +229,7 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void); void ui_statusbar_new(const int win); -gboolean ui_get_char(char *input); +char * ui_readline(void); void ui_input_clear(void); void ui_input_nonblocking(gboolean); void ui_replace_input(char *input, const char * const new_input, int *size); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 6c2d889c..2c7cebf6 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -323,9 +323,9 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void) {} void ui_statusbar_new(const int win) {} -gboolean ui_get_char(char *input) +char * ui_readline(void) { - return FALSE; + return NULL; } void ui_input_clear(void) {} |