Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Jan 14, 2023
1 parent 5a9a1ef commit d57f8ec
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions kilo.c
Expand Up @@ -51,6 +51,7 @@ struct editorConfig {
int screencols;
int numrows;
erow *row;
char *filename;
struct termios orig_termios;
};

Expand Down Expand Up @@ -237,6 +238,9 @@ void editorAppendRow(char *s, size_t len) {
/*** file i/o ***/

void editorOpen(char *filename) {
free(E.filename);
E.filename = strdup(filename);

FILE *fp = fopen(filename, "r");
if (!fp) die("fopen");

Expand Down Expand Up @@ -408,16 +412,26 @@ void editorDrawRows(struct abuf *ab) {
}

abAppend(ab, "\x1b[K", 3);
abAppend(ab, "\r\n", 2);
abAppend(ab, "\r\n", 2);
}
}

void editorDrawStatusBar(struct abuf *ab) {
abAppend(ab, "\x1b[7m", 4);
int len = 0;
char status[80], rstatus[80];
int len = snprintf(status, sizeof(status), "%.20s - %d lines",
E.filename ? E.filename : "[No Name]", E.numrows);
int rlen = snprintf(rstatus, sizeof(rstatus), "%d/%d", E.cy + 1, E.numrows);
if (len > E.screencols) len = E.screencols;
abAppend(ab, status, len);
while (len < E.screencols) {
if (E.screencols - len == rlen) {
abAppend(ab, rstatus, rlen);
break;
} else {
abAppend(ab, " ", 1);
len++;
}
}
abAppend(ab, "\x1b[m", 3);
}
Expand Down Expand Up @@ -453,6 +467,7 @@ void initEditor() {
E.coloff = 0;
E.numrows = 0;
E.row = NULL;
E.filename = NULL;

if (getWindowSize(&E.screenrows, &E.screencols) == -1) die("getWindowSize");
E.screenrows -= 1;
Expand Down

0 comments on commit d57f8ec

Please sign in to comment.