From b00e74f3b825ffb38d6d36ce411441f1148ac433 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Tue, 12 Apr 2022 11:37:35 +0300 Subject: [PATCH 1/4] Allow /editor while not connected Since /editor can be used also for commands it doesn't make sense to restrict it to only connected state. --- src/command/cmd_funcs.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 4fd9d20b..15bf5d7c 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9511,13 +9511,6 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args) { - jabber_conn_status_t conn_status = connection_get_status(); - - if (conn_status != JABBER_CONNECTED) { - cons_show("You are currently not connected."); - return TRUE; - } - gchar* message = NULL; if (get_message_from_editor(NULL, &message)) { From 026522534b0c70e36cb6d94b27515f7162d930a4 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Tue, 12 Apr 2022 11:39:41 +0300 Subject: [PATCH 2/4] Show Readline prompt in input window When doing an interactive search the prompt is needed to show the current state of the search to avoid confusion. --- src/ui/inputwin.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 4a6cae27..de4a838b 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -320,8 +320,15 @@ _inp_win_update_virtual(void) static void _inp_write(char* line, int offset) { + int x; + int y __attribute__((unused)); int col = _inp_offset_to_col(line, offset); werase(inp_win); + + waddstr(inp_win, rl_display_prompt); + getyx(inp_win, y, x); + col += x; + waddstr(inp_win, line); wmove(inp_win, 0, col); _inp_win_handle_scroll(); From ccede06a658bf609ba5cf5b536740d4983b02603 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Tue, 12 Apr 2022 11:40:48 +0300 Subject: [PATCH 3/4] Handle input win redisplay via Readline hook Allow Readline to control when to redisplay the input line. This makes text entered via /editor visible after editor is closed. --- src/ui/inputwin.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index de4a838b..60a0e36f 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -95,6 +95,7 @@ static int _inp_edited(const wint_t ch); static void _inp_win_handle_scroll(void); static int _inp_offset_to_col(char* str, int offset); static void _inp_write(char* line, int offset); +static void _inp_redisplay(void); static void _inp_rl_addfuncs(void); static int _inp_rl_getc(FILE* stream); @@ -149,6 +150,7 @@ create_input_window(void) rl_readline_name = "profanity"; _inp_rl_addfuncs(); rl_getc_function = _inp_rl_getc; + rl_redisplay_function = _inp_redisplay; rl_startup_hook = _inp_rl_startup_hook; rl_callback_handler_install(NULL, _inp_rl_linehandler); @@ -190,9 +192,6 @@ inp_readline(void) } ui_reset_idle_time(); - if (!get_password) { - _inp_write(rl_line_buffer, rl_point); - } inp_nonblocking(TRUE); } else { inp_nonblocking(FALSE); @@ -585,6 +584,14 @@ _inp_rl_getc(FILE* stream) return ch; } +static void +_inp_redisplay(void) +{ + if (!get_password) { + _inp_write(rl_line_buffer, rl_point); + } +} + static int _inp_rl_win_clear_handler(int count, int key) { From 8e728fee157ea96bb6e96a485a11d5a638bd6c98 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 11 Apr 2022 13:43:22 +0300 Subject: [PATCH 4/4] Show return symbol for embedded newlines When editing multi-line messages or comments everything past the first newline becomes invisible. This patch fixes it by substituting a Unicode symbol for "return" instead of printing the newline as is. On locales where it's not available single backslash is used instead. --- src/ui/inputwin.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 60a0e36f..caab9ff1 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -328,7 +328,30 @@ _inp_write(char* line, int offset) getyx(inp_win, y, x); col += x; - waddstr(inp_win, line); + for (size_t i = 0; line[i] != '\0'; i++) { + char* c = &line[i]; + char retc[MB_CUR_MAX]; + + size_t ch_len = mbrlen(c, MB_CUR_MAX, NULL); + if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) { + waddch(inp_win, ' '); + continue; + } + + if (line[i] == '\n') { + c = retc; + ch_len = wctomb(retc, L'\u23ce'); /* return symbol */ + if (ch_len == -1) { /* not representable */ + retc[0] = '\\'; + ch_len = 1; + } + } else { + i += ch_len - 1; + } + + waddnstr(inp_win, c, ch_len); + } + wmove(inp_win, 0, col); _inp_win_handle_scroll();