gitignore, reformat

This commit is contained in:
Tyrel Souza 2021-10-20 23:14:49 -04:00
parent 5332dd8809
commit d9d2fc4a36
2 changed files with 26 additions and 17 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
cmake-*

8
kilo.c
View File

@ -15,6 +15,7 @@
/*** data ***/ /*** data ***/
struct editorConfig { struct editorConfig {
int cx, cy;
int screenrows; int screenrows;
int screencols; int screencols;
struct termios orig_termios; struct termios orig_termios;
@ -87,12 +88,14 @@ int getWindowSize(int *rows, int *cols) {
return 0; return 0;
} }
} }
/*** append buffer ***/ /*** append buffer ***/
struct abuf { struct abuf {
char *b; char *b;
int len; int len;
}; };
#define ABUF_INIT {NULL, 0} #define ABUF_INIT {NULL, 0}
void abAppend(struct abuf *ab, const char *s, int len) { void abAppend(struct abuf *ab, const char *s, int len) {
char *new = realloc(ab->b, ab->len + len); char *new = realloc(ab->b, ab->len + len);
@ -101,6 +104,7 @@ void abAppend(struct abuf *ab, const char *s, int len) {
ab->b = new; ab->b = new;
ab->len += len; ab->len += len;
} }
void abFree(struct abuf *ab) { void abFree(struct abuf *ab) {
free(ab->b); free(ab->b);
} }
@ -130,6 +134,7 @@ void editorDrawRows(struct abuf *ab) {
} }
} }
} }
void editorRefreshScreen() { void editorRefreshScreen() {
struct abuf ab = ABUF_INIT; struct abuf ab = ABUF_INIT;
abAppend(&ab, "\x1b[?25l", 6); abAppend(&ab, "\x1b[?25l", 6);
@ -157,8 +162,11 @@ void editorProcessKeypress() {
/*** init ***/ /*** init ***/
void initEditor() { void initEditor() {
E.cx = 0;
E.cy = 0;
if (getWindowSize(&E.screenrows, &E.screencols) == -1) die("getWindowSize"); if (getWindowSize(&E.screenrows, &E.screencols) == -1) die("getWindowSize");
} }
int main() { int main() {
enableRawMode(); enableRawMode();
initEditor(); initEditor();