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 d3231b8b..b5caa258 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -83,6 +83,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 @@ -136,11 +137,7 @@ wint_t inp_get_char(char *input, int *result) { wint_t ch; - int display_size = 0; - - if (inp_size != 0) { - display_size = g_utf8_strlen(input, inp_size); - } + int display_size = _get_display_length(input); // echo off, and get some more input noecho(); @@ -253,13 +250,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); @@ -293,11 +307,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); |