int main(int argc, char *argv[]) { kbd_event_t ev; int rc; if (argc != 3) { print_syntax(); return 1; } rc = conn_open(argv[1], argv[2]); if (rc != EOK) { printf("Error connecting.\n"); return 1; } printf("Connection established.\n"); con = console_init(stdin, stdout); done = false; while (!done) { console_get_kbd_event(con, &ev); if (ev.type == KEY_PRESS) key_handle(&ev); } return 0; }
/** Get char without timeout * */ int twait(void) { wchar_t c = 0; while (c == 0) { kbd_event_t event; if (!console_get_kbd_event(console, &event)) return -1; if (event.type == KEY_PRESS) c = event.c; } return (int) c; }
static int input_fibril(void *arg) { console_ctrl_t *con; kbd_event_t ev; con = console_init(stdin, stdout); printf("[Press Ctrl-Q to quit]\n"); while (true) { if (!console_get_kbd_event(con, &ev)) break; if (ev.type == KEY_PRESS && (ev.mods & (KM_ALT | KM_SHIFT)) == 0 && (ev.mods & KM_CTRL) != 0) { /* Ctrl+key */ if (ev.key == KC_Q) { ping_signal_done(); return 0; } } } return 0; }
/** Ask for a file name. */ static char *filename_prompt(char const *prompt, char const *init_value) { kbd_event_t ev; char *str; wchar_t buffer[INFNAME_MAX_LEN + 1]; int max_len; int nc; bool done; asprintf(&str, "%s: %s", prompt, init_value); status_display(str); console_set_pos(con, 1 + str_length(str), scr_rows - 1); free(str); console_set_style(con, STYLE_INVERTED); max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); str_to_wstr(buffer, max_len + 1, init_value); nc = wstr_length(buffer); done = false; while (!done) { console_get_kbd_event(con, &ev); if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && (ev.mods & KM_CTRL) != 0) { ; } else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) { switch (ev.key) { case KC_ESCAPE: return NULL; case KC_BACKSPACE: if (nc > 0) { putchar('\b'); console_flush(con); --nc; } break; case KC_ENTER: done = true; break; default: if (ev.c >= 32 && nc < max_len) { putchar(ev.c); console_flush(con); buffer[nc++] = ev.c; } break; } } } } buffer[nc] = '\0'; str = wstr_to_astr(buffer); console_set_style(con, STYLE_NORMAL); return str; }
int main(int argc, char *argv[]) { kbd_event_t ev; coord_t coord; bool new_file; spt_t pt; con = console_init(stdin, stdout); console_clear(con); console_get_size(con, &scr_columns, &scr_rows); pane.rows = scr_rows - 1; pane.columns = scr_columns; pane.sh_row = 1; pane.sh_column = 1; /* Start with an empty sheet. */ sheet_init(&doc.sh); /* Place caret at the beginning of file. */ coord.row = coord.column = 1; sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); pane.ideal_column = coord.column; if (argc == 2) { doc.file_name = str_dup(argv[1]); } else if (argc > 1) { printf("Invalid arguments.\n"); return -2; } else { doc.file_name = NULL; } new_file = false; if (doc.file_name == NULL || file_insert(doc.file_name) != EOK) new_file = true; /* Move to beginning of file. */ caret_move(-ED_INFTY, -ED_INFTY, dir_before); /* Place selection start tag. */ tag_get_pt(&pane.caret_pos, &pt); sheet_place_tag(&doc.sh, &pt, &pane.sel_start); /* Initial display */ cursor_visible = true; cursor_hide(); console_clear(con); pane_text_display(); pane_status_display(); if (new_file && doc.file_name != NULL) status_display("File not found. Starting empty file."); pane_caret_display(); cursor_show(); done = false; while (!done) { console_get_kbd_event(con, &ev); pane.rflags = 0; if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_SHIFT) == 0) && (ev.mods & KM_CTRL) != 0) { key_handle_ctrl(&ev); } else if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_CTRL) == 0) && (ev.mods & KM_SHIFT) != 0) { key_handle_shift(&ev); } else if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { key_handle_unmod(&ev); } } /* Redraw as necessary. */ cursor_hide(); if (pane.rflags & REDRAW_TEXT) pane_text_display(); if (pane.rflags & REDRAW_ROW) pane_row_display(); if (pane.rflags & REDRAW_STATUS) pane_status_display(); if (pane.rflags & REDRAW_CARET) pane_caret_display(); cursor_show(); } console_clear(con); return 0; }