static void ui_terminal_restore(Ui *ui) { UiCurses *uic = (UiCurses*)ui; termkey_start(uic->termkey); reset_prog_mode(); wclear(stdscr); curs_set(0); }
int main(int argc, char *argv[]) { TermKey *tk; plan_tests(6); tk = termkey_new_abstract("vt100", 0); ok(!!tk, "termkey_new_abstract"); is_int(termkey_get_buffer_size(tk), 256, "termkey_get_buffer_size"); ok(termkey_is_started(tk), "termkey_is_started true after construction"); termkey_stop(tk); ok(!termkey_is_started(tk), "termkey_is_started false after termkey_stop()"); termkey_start(tk); ok(termkey_is_started(tk), "termkey_is_started true after termkey_start()"); termkey_destroy(tk); ok(1, "termkey_free"); return exit_status(); }
TermKey *termkey_new(int fd, int flags) { TermKey *tk = termkey_alloc(); if(!tk) return NULL; tk->fd = fd; if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) { char *e; /* Most OSes will set .UTF-8. Some will set .utf8. Try to be fairly * generous in parsing these */ if(((e = getenv("LANG")) || (e = getenv("LC_MESSAGES")) || (e = getenv("LC_ALL"))) && (e = strchr(e, '.')) && e++ && (strcaseeq(e, "UTF-8") || strcaseeq(e, "UTF8"))) flags |= TERMKEY_FLAG_UTF8; else flags |= TERMKEY_FLAG_RAW; } termkey_set_flags(tk, flags); const char *term = getenv("TERM"); if(!termkey_init(tk, term)) goto abort; if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk)) goto abort; return tk; abort: free(tk); return NULL; }
TermKey *termkey_new_abstract(const char *term, int flags) { TermKey *tk = termkey_alloc(); if(!tk) return NULL; tk->fd = -1; termkey_set_flags(tk, flags); if(!termkey_init(tk, term)) { free(tk); return NULL; } if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk)) goto abort; return tk; abort: free(tk); return NULL; }