diff --git a/src/profanity.c b/src/profanity.c index ad074f6a..30a55b0c 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -77,7 +77,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name) _init(disable_tls, log_level); char inp[INP_WIN_MAX]; - int size = 0; char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT); if (account_name != NULL) { @@ -94,18 +93,20 @@ prof_run(const int disable_tls, char *log_level, char *account_name) log_info("Starting main event loop"); jabber_conn_status_t conn_status = jabber_get_connection_status(); + int size = 0; + gboolean read_input = TRUE; gboolean cmd_result = TRUE; - while(cmd_result == TRUE) { - wint_t ch = ERR; - size = 0; - while(ch != '\n') { + while(cmd_result == TRUE) { + size = 0; + read_input = TRUE; + while(read_input) { conn_status = jabber_get_connection_status(); if (conn_status == JABBER_CONNECTED) { _handle_idle_time(); } - ch = ui_get_char(inp, &size); + read_input = ui_get_char(inp, &size); #ifdef HAVE_LIBOTR otr_poll(); @@ -115,7 +116,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name) ui_update(); } - inp[size++] = '\0'; cmd_result = process_input(inp); } } diff --git a/src/ui/core.c b/src/ui/core.c index 6918a658..50fa8539 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -174,7 +174,7 @@ ui_close(void) endwin(); } -wint_t +gboolean ui_get_char(char *input, int *size) { int result = 0; @@ -193,7 +193,11 @@ ui_get_char(char *input, int *size) ui_input_nonblocking(FALSE); } - return ch; + if (ch == '\n') { + input[*size++] = '\0'; + } + + return (ch != '\n'); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 1e78ce40..a482826b 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); -wint_t ui_get_char(char *input, int *size); +gboolean ui_get_char(char *input, int *size); 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 cee10aa9..e5588cad 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) {} -wint_t ui_get_char(char *input, int *size) +gboolean ui_get_char(char *input, int *size) { - return 0; + return FALSE; } void ui_input_clear(void) {}