diff options
-rw-r--r-- | src/ui/inputwin.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 43eaeba8..fbfd1e3a 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -86,6 +86,7 @@ static void _handle_backspace(int display_size, int inp_x, char *input); static int _printable(const wint_t ch); static void _clear_input(void); static void _go_to_end(int display_size); +static int _get_display_length(char *input); static void _delete_previous_word(char *input); void @@ -138,11 +139,7 @@ inp_block(void) char * inp_get_char(int *key_type, wint_t *ch) { - int display_size = 0; - - if (inp_size != 0) { - display_size = g_utf8_strlen(line, inp_size); - } + int display_size = _get_display_length(line); // echo off, and get some more input noecho(); @@ -257,13 +254,30 @@ inp_put_back(void) _inp_win_update_virtual(); } +static int +_get_display_length(char *input) +{ + int len = 0; + gchar *curr = g_utf8_offset_to_pointer(input, 0); + while (*curr != '\0') { + gunichar curru = g_utf8_get_char(curr); + if (g_unichar_iswide(curru)) { + len += 2; + } else { + len ++; + } + curr = g_utf8_next_char(curr); + } + + return len; +} + void inp_replace_input(char *input, const char * const new_input, int *size) { - int display_size; strncpy(input, new_input, INP_WIN_MAX); *size = strlen(input); - display_size = g_utf8_strlen(input, *size); + int display_size = _get_display_length(input); inp_win_reset(); input[*size] = '\0'; waddstr(inp_win, input); @@ -297,11 +311,7 @@ _handle_edit(int result, const wint_t ch, char *input) char *next = NULL; int inp_x = 0; int next_ch; - int display_size = 0; - - if (inp_size != 0) { - display_size = g_utf8_strlen(input, inp_size); - } + int display_size = _get_display_length(input); inp_x = getcurx(inp_win); |