#define _DEFAULT_SOURCE #define _BSD_SOURCE #define _GNU_SOURCE #include // for signal, SIGWINCH #include // for exit #include // for NULL #include // for STDOUT_FILENO #include "fn.h" #include "file.h" // for editorOpen #include "input.h" // for editorProcessKeypress #include "output.h" // for editorRefreshScreen, editorSetStatusMessage #include "terminal.h" // for die, setWindowSize, enableRawMode void windowResizeCallback(int signum) { if (signum != SIGWINCH) { return; } if (setWindowSize(&E.screenrows, &E.screencols) == -1) { die("setWindowSize"); } E.screenrows -= 2; editorRefreshScreen(); } void initEditor() { E.cx = 0; E.cy = 0; E.rx = 0; E.rowoff = 0; E.coloff = 0; E.numrows = 0; E.row = NULL; E.dirty = 0; E.filename = NULL; E.statusmsg[0] = '\0'; E.statusmsg_time = 0; E.syntax = NULL; if (setWindowSize(&E.screenrows, &E.screencols) == -1) { die("setWindowSize"); } E.screenrows -= 2; } void exitEditor() { // Restore from raw mode and exit write(STDOUT_FILENO, "\x1b[2J", 4); write(STDOUT_FILENO, "\x1b[H", 3); exit(0); } int main(int argc, char *argv[]) { enableRawMode(); initEditor(); if (argc >= 2) { editorOpen(argv[1]); } editorSetStatusMessage("Ctrl-C = Quit, Ctrl-S = save, Ctrl-F = find"); signal(SIGWINCH, windowResizeCallback); while (1) { editorRefreshScreen(); editorProcessKeypress(); } exitEditor(); return 0; }