diff options
-rw-r--r-- | src/input_win.c | 63 | ||||
-rw-r--r-- | src/profanity.c | 4 | ||||
-rw-r--r-- | src/ui.h | 6 | ||||
-rw-r--r-- | src/windows.c | 10 |
4 files changed, 51 insertions, 32 deletions
diff --git a/src/input_win.c b/src/input_win.c index c809454e..470f7cb9 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -38,11 +38,12 @@ * pad_start : 3 * cols : 4 */ - +#define _XOPEN_SOURCE_EXTENDED #include "config.h" #include <stdlib.h> #include <string.h> +#include <wchar.h> #ifdef HAVE_NCURSES_H #include <ncurses.h> @@ -64,9 +65,9 @@ static WINDOW *inp_win; static int pad_start = 0; -static int _handle_edit(const int ch, char *input, int *size); -static int _printable(const int ch); -static gboolean _special_key(const int ch); +static int _handle_edit(const wint_t ch, char *input, int *size); +static int _printable(const wint_t ch); +static gboolean _special_key(const wint_t ch); void create_input_window(void) @@ -128,59 +129,73 @@ inp_block(void) wtimeout(inp_win, -1); } -void -inp_get_char(int *ch, char *input, int *size) +wint_t +inp_get_char(char *input, int *size) { int inp_y = 0; int inp_x = 0; int i; + wint_t ch; + int display_size = 0; + + if (*size != 0) { + display_size = g_utf8_strlen(input, *size); + } // echo off, and get some more input noecho(); - *ch = wgetch(inp_win); + wget_wch(inp_win, &ch); gboolean in_command = FALSE; - if ((*size >= 1 && input[0] == '/') || - (*size == 0 && *ch == '/')) { + if ((display_size > 0 && input[0] == '/') || + (display_size == 0 && ch == '/')) { in_command = TRUE; } if (prefs_get_states()) { - if (*ch == ERR) { + if (ch == ERR) { prof_handle_idle(); } - if (prefs_get_outtype() && (*ch != ERR) && !in_command - && _printable(*ch)) { + if (prefs_get_outtype() && (ch != ERR) && !in_command + && _printable(ch)) { prof_handle_activity(); } } // if it wasn't an arrow key etc - if (!_handle_edit(*ch, input, size)) { - if (_printable(*ch)) { + if (!_handle_edit(ch, input, size)) { + if (_printable(ch)) { getyx(inp_win, inp_y, inp_x); // handle insert if not at end of input - if (inp_x < *size) { - winsch(inp_win, *ch); + if (inp_x < display_size) { + winsch(inp_win, ch); wmove(inp_win, inp_y, inp_x+1); for (i = *size; i > inp_x; i--) input[i] = input[i-1]; - input[inp_x] = *ch; + input[inp_x] = ch; (*size)++; // otherwise just append } else { - waddch(inp_win, *ch); - input[(*size)++] = *ch; + cchar_t t = { 0, { ch, 0 } }; + wadd_wch(inp_win, &t); + char bytes[5]; + size_t utf_len = wcrtomb(bytes, ch, NULL); + int i; + for (i = 0 ; i < utf_len; i++) { + int .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ |