Skip to content

Commit

Permalink
https://viewsourcecode.org/snaptoken/kilo/03.rawInputAndOutput.html#g…
Browse files Browse the repository at this point in the history
…lobal-state
  • Loading branch information
Gurrium committed Dec 18, 2022
1 parent d465810 commit 216b75e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kilo.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 216b75e

Please sign in to comment.