diff options
author | James Booth <boothj5@gmail.com> | 2015-01-15 22:53:50 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-15 22:53:50 +0000 |
commit | e326aaa84fd6a3f403e0ec80e02e2b766a5f74c7 (patch) | |
tree | 0a6cb9d1cc0ece646a90a5173a9be46fc23955d3 /src/ui | |
parent | 173a3a82bb196baf2d8cb7a093ffb6a594830e50 (diff) | |
parent | ad896ef201a92acb02b208013bc4ed996204a2df (diff) | |
download | profani-tty-e326aaa84fd6a3f403e0ec80e02e2b766a5f74c7.tar.gz |
Merge branch 'master' into inp-utf8
Conflicts: src/ui/inputwin.c
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/core.c | 11 | ||||
-rw-r--r-- | src/ui/inputwin.c | 110 | ||||
-rw-r--r-- | src/ui/inputwin.h | 2 |
3 files changed, 61 insertions, 62 deletions
diff --git a/src/ui/core.c b/src/ui/core.c index f1a563d7..45dd2a08 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -182,14 +182,7 @@ 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; - } + wint_t ch = inp_get_char(input, &result); _win_handle_switch(ch); @@ -207,7 +200,7 @@ ui_readline(void) ui_input_nonblocking(FALSE); } - if (return_line) { + if (ch == '\n') { return input; } else { return NULL; diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index ecbeeb29..b5caa258 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -75,15 +75,16 @@ static WINDOW *inp_win; static int pad_start = 0; static int rows, cols; +static int inp_size; -static int _handle_edit(int result, const wint_t ch, char *input, int *size); -static int _handle_alt_key(char *input, int *size, int key); -static void _handle_backspace(int display_size, int inp_x, int *size, char *input); +static int _handle_edit(int result, const wint_t ch, char *input); +static int _handle_alt_key(char *input, int key); +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, int *size); +static void _delete_previous_word(char *input); void create_input_window(void) @@ -133,7 +134,7 @@ inp_block(void) } wint_t -inp_get_char(char *input, int *size, int *result) +inp_get_char(char *input, int *result) { wint_t ch; int display_size = _get_display_length(input); @@ -156,9 +157,9 @@ inp_get_char(char *input, int *size, int *result) } // if it wasn't an arrow key etc - if (!_handle_edit(*result, ch, input, size)) { + if (!_handle_edit(*result, ch, input)) { if (_printable(ch) && *result != KEY_CODE_YES) { - if (*size >= INP_WIN_MAX) { + if (inp_size >= INP_WIN_MAX) { return ERR; } @@ -171,7 +172,7 @@ inp_get_char(char *input, int *size, int *result) char *next_ch = g_utf8_offset_to_pointer(input, inp_x); char *offset; - for (offset = &input[*size - 1]; offset >= next_ch; offset--) { + for (offset = &input[inp_size - 1]; offset >= next_ch; offset--) { *(offset + utf_len) = *offset; } int i; @@ -179,8 +180,8 @@ inp_get_char(char *input, int *size, int *result) *(next_ch + i) = bytes[i]; } - *size += utf_len; - input[*size] = '\0'; + inp_size += utf_len; + input[inp_size] = '\0'; waddstr(inp_win, next_ch); wmove(inp_win, 0, inp_x + 1); @@ -198,9 +199,9 @@ inp_get_char(char *input, int *size, int *result) if (utf_len < MB_CUR_MAX) { int i; for (i = 0 ; i < utf_len; i++) { - input[(*size)++] = bytes[i]; + input[inp_size++] = bytes[i]; } - input[*size] = '\0'; + input[inp_size] = '\0'; bytes[utf_len] = '\0'; waddstr(inp_win, bytes); @@ -222,6 +223,11 @@ inp_get_char(char *input, int *size, int *result) echo(); + if (ch == '\n') { + input[inp_size++] = '\0'; + inp_size = 0; + } + return ch; } @@ -295,7 +301,7 @@ _clear_input(void) * return 0 if it wasn't */ static int -_handle_edit(int result, const wint_t ch, char *input, int *size) +_handle_edit(int result, const wint_t ch, char *input) { char *prev = NULL; char *next = NULL; @@ -307,7 +313,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) // CTRL-LEFT if ((result == KEY_CODE_YES) && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539) && (inp_x > 0)) { - input[*size] = '\0'; + input[inp_size] = '\0'; gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x); curr_ch = g_utf8_find_prev_char(input, curr_ch); gchar *prev_ch; @@ -357,7 +363,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) // CTRL-RIGHT } else if ((result == KEY_CODE_YES) && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554) && (inp_x < display_size)) { - input[*size] = '\0'; + input[inp_size] = '\0'; gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x); gchar *next_ch = g_utf8_find_next_char(curr_ch, NULL); gunichar curr_uni; @@ -416,21 +422,21 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) // check for ALT-key next_ch = wgetch(inp_win); if (next_ch != ERR) { - return _handle_alt_key(input, size, next_ch); + return _handle_alt_key(input, next_ch); } else { - *size = 0; + inp_size = 0; inp_win_reset(); return 1; } case 127: - _handle_backspace(display_size, inp_x, size, input); + _handle_backspace(display_size, inp_x, input); return 1; case KEY_BACKSPACE: if (result != KEY_CODE_YES) { return 0; } - _handle_backspace(display_size, inp_x, size, input); + _handle_backspace(display_size, inp_x, input); return 1; case KEY_DC: // DEL @@ -440,10 +446,10 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) case KEY_CTRL_D: if (inp_x == display_size-1) { gchar *start = g_utf8_substring(input, 0, inp_x); - for (*size = 0; *size < strlen(start); (*size)++) { - input[*size] = start[*size]; + for (inp_size = 0; inp_size < strlen(start); inp_size++) { + input[inp_size] = start[inp_size]; } - input[*size] = '\0'; + input[inp_size] = '\0'; g_free(start); @@ -451,14 +457,14 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) waddstr(inp_win, input); } else if (inp_x < display_size-1) { gchar *start = g_utf8_substring(input, 0, inp_x); - gchar *end = g_utf8_substring(input, inp_x+1, *size); + gchar *end = g_utf8_substring(input, inp_x+1, inp_size); GString *new = g_string_new(start); g_string_append(new, end); - for (*size = 0; *size < strlen(new->str); (*size)++) { - input[*size] = new->str[*size]; + for (inp_size = 0; inp_size < strlen(new->str); inp_size++) { + input[inp_size] = new->str[inp_size]; } - input[*size] = '\0'; + input[inp_size] = '\0'; g_free(start); g_free(end); @@ -507,9 +513,9 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) return 0; } case KEY_CTRL_P: - prev = cmd_history_previous(input, size); + prev = cmd_history_previous(input, &inp_size); if (prev) { - inp_replace_input(input, prev, size); + inp_replace_input(input, prev, &inp_size); } return 1; @@ -518,13 +524,13 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) return 0; } case KEY_CTRL_N: - next = cmd_history_next(input, size); + next = cmd_history_next(input, &inp_size); if (next) { - inp_replace_input(input, next, size); - } else if (*size != 0) { - input[*size] = '\0'; + inp_replace_input(input, next, &inp_size); + } else if (inp_size != 0) { + input[inp_size] = '\0'; cmd_history_append(input); - inp_replace_input(input, "", size); + inp_replace_input(input, "", &inp_size); } return 1; @@ -547,23 +553,23 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) return 1; case 9: // tab - if (*size != 0) { + if (inp_size != 0) { if ((strncmp(input, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { - muc_autocomplete(input, size); + muc_autocomplete(input, &inp_size); } else if (strncmp(input, "/", 1) == 0) { - cmd_autocomplete(input, size); + cmd_autocomplete(input, &inp_size); } } return 1; case KEY_CTRL_W: - _delete_previous_word(input, size); + _delete_previous_word(input); return 1; break; case KEY_CTRL_U: while (getcurx(inp_win) > 0) { - _delete_previous_word(input, size); + _delete_previous_word(input); } return 1; break; @@ -575,7 +581,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size) } static void -_handle_backspace(int display_size, int inp_x, int *size, char *input) +_handle_backspace(int display_size, int inp_x, char *input) { roster_reset_search_attempts(); if (display_size > 0) { @@ -583,10 +589,10 @@ _handle_backspace(int display_size, int inp_x, int *size, char *input) // if at end, delete last char if (inp_x >= display_size) { gchar *start = g_utf8_substring(input, 0, inp_x-1); - for (*size = 0; *size < strlen(start); (*size)++) { - input[*size] = start[*size]; + for (inp_size = 0; inp_size < strlen(start); inp_size++) { + input[inp_size] = start[inp_size]; } - input[*size] = '\0'; + input[inp_size] = '\0'; g_free(start); @@ -597,14 +603,14 @@ _handle_backspace(int display_size, int inp_x, int *size, char *input) // if in middle, delete and shift chars left } else if (inp_x > 0 && inp_x < display_size) { gchar *start = g_utf8_substring(input, 0, inp_x - 1); - gchar *end = g_utf8_substring(input, inp_x, *size); + gchar *end = g_utf8_substring(input, inp_x, inp_size); GString *new = g_string_new(start); g_string_append(new, end); - for (*size = 0; *size < strlen(new->str); (*size)++) { - input[*size] = new->str[*size]; + for (inp_size = 0; inp_size < strlen(new->str); inp_size++) { + input[inp_size] = new->str[inp_size]; } - input[*size] = '\0'; + input[inp_size] = '\0'; g_free(start); g_free(end); @@ -629,7 +635,7 @@ _handle_backspace(int display_size, int inp_x, int *size, char *input) } static int -_handle_alt_key(char *input, int *size, int key) +_handle_alt_key(char *input, int key) { switch (key) { @@ -671,7 +677,7 @@ _handle_alt_key(char *input, int *size, int key) break; case 263: case 127: - _delete_previous_word(input, size); + _delete_previous_word(input); break; default: break; @@ -680,12 +686,12 @@ _handle_alt_key(char *input, int *size, int key) } static void -_delete_previous_word(char *input, int *size) +_delete_previous_word(char *input) { int end_del = getcurx(inp_win); int start_del = end_del; - input[*size] = '\0'; + input[inp_size] = '\0'; gchar *curr_ch = g_utf8_offset_to_pointer(input, end_del); curr_ch = g_utf8_find_prev_char(input, curr_ch); gchar *prev_ch; @@ -731,8 +737,8 @@ _delete_previous_word(char *input, int *size) input[strlen(start_string)+i] = end_string[i]; } - *size = strlen(start_string)+i; - input[*size] = '\0'; + inp_size = strlen(start_string)+i; + input[inp_size] = '\0'; _clear_input(); waddstr(inp_win, input); diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index b5a26c10..8a01745d 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -36,7 +36,7 @@ #define UI_INPUTWIN_H void create_input_window(void); -wint_t inp_get_char(char *input, int *size, int *result); +wint_t inp_get_char(char *input, int *result); void inp_win_reset(void); void inp_win_resize(void); void inp_put_back(void); |