diff --git a/kilo.c b/kilo.c index 6942bf4..9cb430b 100644 --- a/kilo.c +++ b/kilo.c @@ -18,6 +18,9 @@ struct termios orig_termios; /*** terminal ***/ void die(const char *s) { + write(STDOUT_FILENO, "\x1b[2J", 4); + write(STDOUT_FILENO, "\x1b[H", 3); + perror(s); exit(1); } @@ -56,17 +59,39 @@ void editorProcessKeyPress() { switch (c) { case CTRL_KEY('q'): + write(STDOUT_FILENO, "\x1b[2J", 4); + write(STDOUT_FILENO, "\x1b[H", 3); + exit(0); break; } } +/*** output ***/ + +void editorDrawRows() { + int y; + for (y = 0; y < 24; y++) { + write(STDOUT_FILENO, "~\r\n", 3); + } +} + +void editorRefreshScreen() { + write(STDOUT_FILENO, "\x1b[2J", 4); + write(STDOUT_FILENO, "\x1b[H", 3); + + editorDrawRows(); + + write(STDIN_FILENO, "\x1b[H", 3); +} + /*** init ***/ int main() { enableRawMode(); while (1) { + editorRefreshScreen(); editorProcessKeyPress(); }