diff --git a/kilo.c b/kilo.c index a67b458..a64bd18 100644 --- a/kilo.c +++ b/kilo.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -76,8 +77,8 @@ int getCursorPosition(int *rows, int *cols) { if (buf[0] != '\x1b' || buf[1] != '[') return -1; if (sscanf(&buf[2], "%d;%d", rows, cols) != 2) return -1; - - return 0; + + return 0; } int getWindowSize(int *rows, int *cols) { @@ -93,7 +94,30 @@ int getWindowSize(int *rows, int *cols) { } } +/*** append buffer ***/ +struct abuf { + char *b; + int len; +}; + +#define ABUF_INIT \ + { NULL, 0 } + +void abAppend(struct abuf *ab, const char *s, int len) { + char *new = realloc(ab->b, ab->len + len); + + if (new == NULL) return; + memcpy(&new[ab->len], s, len); + ab->b = new; + ab->len = += len; +} + +void abFree(struct abuf *ab) { + free(ab->b) +} + /*** input ***/ + void editorProcessKeyPress() { char c = editorReadKey(); @@ -112,7 +136,11 @@ void editorProcessKeyPress() { void editorDrawRows() { int y; for (y = 0; y < E.screenrows; y++) { - write(STDOUT_FILENO, "~\r\n", 3); + write(STDIN_FILENO, "~", 1); + + if (y < E.screenrows - 1) { + write(STDIN_FILENO, "\r\n", 2); + } } }