about summary refs log blame commit diff stats
path: root/src/kilo.c
blob: 4a5bf5234a0c5fc3b2093231acf55c49e9b0c0ac (plain) (tree)
ass="w"> || c == ENTER) { if (c == ENTER) { save_to_current_definition_and_editor_buffer(L, query); clearEditor(); editorOpen("teliva_editor_buffer"); } return; } else if (c == CTRL_U) { qlen = 0; query[qlen] = '\0'; } else if (isprint(c)) { if (qlen < CURRENT_DEFINITION_LEN) { query[qlen++] = c; query[qlen] = '\0'; } } } } /* Process events arriving from the standard input, which is, the user * is typing stuff on the terminal. */ static int Quit = 0; static int Back_to_big_picture = 0; extern void save_editor_state(int rowoff, int coloff, int cy, int cx); static void editorProcessKeypress(lua_State* L) { int c = getch(); //? mvprintw(LINES-3, 60, "key: %d\n", c); //? getch(); switch(c) { case ENTER: { editorInsertNewline(); /* auto-indent */ erow* prevrow = &E.row[E.rowoff + E.cy - 1]; for (int x = 0; x < prevrow->size && prevrow->chars[x] == ' '; ++x) editorInsertChar(' '); } break; case CTRL_C: if (Previous_error != NULL) exit(1); break; case CTRL_E: /* Save and quit. */ editorSaveToDisk(); save_editor_state(E.rowoff, E.coloff, E.cy, E.cx); Quit = 1; break; case CTRL_G: /* Go to a different definition. */ editorGo(L); break; case CTRL_B: /* Go to big-picture view. */ editorSaveToDisk(); Quit = 1; Back_to_big_picture = 1; break; case CTRL_F: editorFind(); break; case KEY_BACKSPACE: case DELETE: case CTRL_H: editorDelChar(); break; case KEY_NPAGE: case KEY_PPAGE: if (c == KEY_PPAGE && E.cy != 0) E.cy = 0; else if (c == KEY_NPAGE && E.cy != LINES-1-1) E.cy = LINES-1-1; { int times = LINES-1; while(times--) editorMoveCursor(c == KEY_PPAGE ? KEY_UP : KEY_DOWN); } break; case CTRL_A: while (!editorAtStartOfLine()) editorMoveCursor(KEY_LEFT); break; case CTRL_L: while (1) { editorMoveCursor(KEY_RIGHT); if (editorAtStartOfLine()) { editorMoveCursor(KEY_LEFT); break; } } break; case CTRL_U: while (!editorAtStartOfLine()) editorDelChar(); break; case CTRL_K: while (1) { editorMoveCursor(KEY_RIGHT); if (editorAtStartOfLine()) { editorMoveCursor(KEY_LEFT); break; } editorDelChar(); } break; case CTRL_SLASH: /* same as CTRL_UNDERSCORE */ if (starts_with(E.row[E.rowoff+E.cy].chars, "--? ")) editorUncommentCursorRow(); else editorCommentCursorRow(); break; case KEY_UP: case KEY_DOWN: case KEY_LEFT: case KEY_RIGHT: editorMoveCursor(c); break; case TAB: /* insert 2 spaces */ editorInsertChar(' '); editorInsertChar(' '); break; default: if (c >= ' ') editorInsertChar(c); break; } } static void initEditor(void) { E.cx = 0; E.cy = 0; E.rowoff = 0; E.coloff = 0; E.numrows = 0; E.row = NULL; E.dirty = 0; E.filename = NULL; E.syntax = &HLDB[0]; } /* return true if user chose to back into the big picture view */ int edit(lua_State* L, char* filename) { Quit = 0; Back_to_big_picture = 0; initEditor(); editorOpen(filename); while(!Quit) { E.cols = COLS-LINE_NUMBER_SPACE; /* update on resize */ editorRefreshScreen(editorMenu); editorProcessKeypress(L); } return Back_to_big_picture; } /* return true if user chose to back into the big picture view */ int edit_from(lua_State* L, char* filename, int rowoff, int coloff, int cy, int cx) { Quit = 0; Back_to_big_picture = 0; initEditor(); E.rowoff = rowoff; E.coloff = coloff; E.cy = cy; E.cx = cx; editorOpen(filename); while(!Quit) { E.cols = COLS-LINE_NUMBER_SPACE; /* update on resize */ editorRefreshScreen(editorMenu); editorProcessKeypress(L); } return Back_to_big_picture; } int resumeEdit(lua_State* L) { Quit = 0; Back_to_big_picture = 0; while(!Quit) { E.cols = COLS-LINE_NUMBER_SPACE; /* update on resize */ editorRefreshScreen(editorMenu); editorProcessKeypress(L); } return Back_to_big_picture; } /* vim:tabstop=4:shiftwidth=0:expandtab:softtabstop=-1 */