void owl_process_input(const owl_io_dispatch *d, void *data) { owl_input j; while (1) { j.ch = wgetch(g.input_pad); if (j.ch == ERR) return; j.uch = '\0'; if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) { /* This is a curses control character. */ } else if (j.ch > 0x7f && j.ch < 0xfe) { /* Pull in a full utf-8 character. */ int bytes, i; char utf8buf[7]; memset(utf8buf, '\0', 7); utf8buf[0] = j.ch; if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2; else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3; else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4; else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5; else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6; else bytes = 1; for (i = 1; i < bytes; i++) { int tmp = wgetch(g.input_pad); /* If what we got was not a byte, or not a continuation byte */ if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) { /* ill-formed UTF-8 code unit subsequence, put back the char we just got. */ ungetch(tmp); j.ch = ERR; break; } utf8buf[i] = tmp; } if (j.ch != ERR) { if (g_utf8_validate(utf8buf, -1, NULL)) { j.uch = g_utf8_get_char(utf8buf); } else { j.ch = ERR; } } } else if (j.ch <= 0x7f) { j.uch = j.ch; } owl_process_input_char(j); } }
void owl_select_handle_intr() { owl_input in; owl_global_unset_interrupted(&g); owl_function_unmask_sigint(NULL); in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR]; owl_process_input_char(in); }
static void sig_handler_main_thread(void *data) { int sig = GPOINTER_TO_INT(data); owl_function_debugmsg("Got signal %d", sig); if (sig == SIGWINCH) { owl_function_resize(); } else if (sig == SIGTERM || sig == SIGHUP) { owl_function_quit(); } else if (sig == SIGINT && owl_global_take_interrupt(&g)) { owl_input in; in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR]; owl_process_input_char(in); } }