static Status ti_init(UI *ui) { TUI *tui = (TUI *)ui; /* Termkey */ /* Create new termkey instance monitoring stdin with * the SIGINT behaviour of Ctrl-C disabled */ tui->termkey = termkey_new(STDIN_FILENO, TERMKEY_FLAG_SPACESYMBOL | TERMKEY_FLAG_CTRLC); if (tui->termkey == NULL) { return st_get_error(ERR_UNABLE_TO_INITIALISE_TERMEKEY, "Unable to create termkey instance"); } /* Represent ASCII DEL character as backspace */ termkey_set_canonflags(tui->termkey, TERMKEY_CANON_DELBS | TERMKEY_CANON_SPACESYMBOL); if (tui->sess->wed_opt.test_mode) { tui->rows = 24; tui->cols = 80; return STATUS_SUCCESS; } /* ncurses */ initscr(); tui->rows = LINES; tui->cols = COLS; tv_init(&tui->tv, tui->rows, tui->cols); ti_init_display(ui); refresh(); return STATUS_SUCCESS; }
void CoreManager::initInput() { // init libtermkey TERMKEY_CHECK_VERSION; if (!(tk = termkey_new(STDIN_FILENO, TERMKEY_FLAG_NOTERMIOS))) { g_critical(_("Libtermkey initialization failed.")); exit(1); } termkey_set_canonflags(tk, TERMKEY_CANON_DELBS); utf8 = g_get_charset(NULL); io_input_channel = g_io_channel_unix_new(STDIN_FILENO); // set channel encoding to NULL so it can be unbuffered g_io_channel_set_encoding(io_input_channel, NULL, NULL); g_io_channel_set_buffered(io_input_channel, FALSE); g_io_channel_set_close_on_unref(io_input_channel, TRUE); io_input_channel_id = g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), io_input_, this, NULL); g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH, G_IO_NVAL, io_input_error_, this, NULL); g_io_channel_unref(io_input_channel); // screen resizing if (!pipe(pipefd)) { pipe_valid = true; resize_channel = g_io_channel_unix_new(pipefd[0]); g_io_channel_set_encoding(resize_channel, NULL, NULL); g_io_channel_set_buffered(resize_channel, FALSE); g_io_channel_set_close_on_unref(resize_channel, TRUE); resize_channel_id = g_io_add_watch_full(resize_channel, G_PRIORITY_HIGH, G_IO_IN, resize_input_, this, NULL); } }
Ui *ui_curses_new(void) { UiCurses *uic = calloc(1, sizeof(UiCurses)); Ui *ui = (Ui*)uic; if (!uic) return NULL; if (!(uic->termkey = termkey_new(STDIN_FILENO, TERMKEY_FLAG_UTF8))) goto err; termkey_set_canonflags(uic->termkey, TERMKEY_CANON_DELBS); setlocale(LC_CTYPE, ""); if (!getenv("ESCDELAY")) set_escdelay(50); char *term = getenv("TERM"); if (!term) term = "xterm"; if (!newterm(term, stderr, stdin)) { snprintf(uic->info, sizeof(uic->info), "Warning: unknown term `%s'", term); if (!newterm(strstr(term, "-256color") ? "xterm-256color" : "xterm", stderr, stdin)) goto err; } start_color(); use_default_colors(); raw(); noecho(); nonl(); keypad(stdscr, TRUE); meta(stdscr, TRUE); curs_set(0); /* needed because we use getch() which implicitly calls refresh() which would clear the screen (overwrite it with an empty / unused stdscr */ refresh(); *ui = (Ui) { .init = ui_init, .start = ui_start, .free = ui_curses_free, .termkey_get = ui_termkey_get, .suspend = ui_suspend, .resize = ui_resize, .update = ui_update, .window_new = ui_window_new, .window_free = ui_window_free, .window_focus = ui_window_focus, .window_swap = ui_window_swap, .draw = ui_draw, .redraw = ui_redraw, .arrange = ui_arrange, .die = ui_die, .info = ui_info, .info_hide = ui_info_hide, .haskey = ui_haskey, .getkey = ui_getkey, .terminal_save = ui_terminal_save, .terminal_restore = ui_terminal_restore, }; struct sigaction sa; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sa.sa_handler = sigwinch_handler; sigaction(SIGWINCH, &sa, NULL); sigaction(SIGCONT, &sa, NULL); ui_resize(ui); return ui; err: ui_curses_free(ui); return NULL; }
static TermKey *ui_termkey_new(int fd) { TermKey *termkey = termkey_new(fd, TERMKEY_FLAG_UTF8); if (termkey) termkey_set_canonflags(termkey, TERMKEY_CANON_DELBS); return termkey; }