static void key_handle(kbd_event_t *ev) { 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_CTRL | KM_ALT)) == 0) { key_handle_unmod(ev); } }
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; }