diff --git a/kilo.c b/kilo.c index 2d45865..a818810 100644 --- a/kilo.c +++ b/kilo.c @@ -7,11 +7,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include /*** defines ***/ @@ -52,6 +54,8 @@ struct editorConfig { int numrows; erow *row; char *filename; + char statusmsg[80]; + time_t statusmsg_time; struct termios orig_termios; }; @@ -486,6 +490,23 @@ void editorDrawStatusBar(struct abuf *ab) } abAppend(ab, "\x1b[m", 3); + abAppend(ab, "\r\n", 2); +} + +void editorDrawMessageBar(struct abuf *ab) +{ + abAppend(ab, "\x1b[K", 3); + int msglen = strlen(E.statusmsg); + + if (msglen > E.screencols) + { + msglen = E.screencols; + } + + if (msglen && time(NULL) - E.statusmsg_time < 5) + { + abAppend(ab, E.statusmsg, msglen); + } } void editorRefreshScreen() @@ -499,6 +520,7 @@ void editorRefreshScreen() editorDrawRows(&ab); editorDrawStatusBar(&ab); + editorDrawMessageBar(&ab); char buf[32]; snprintf(buf, sizeof(buf), "\x1b[%d;%dH", @@ -511,6 +533,15 @@ void editorRefreshScreen() abFree(&ab); } +void editorSetStatusMessage(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsnprintf(E.statusmsg, sizeof(E.statusmsg), fmt, ap); + va_end(ap); + E.statusmsg_time = time(NULL); +} + /*** input ***/ void editorMoveCursor(int key) @@ -633,13 +664,15 @@ void initEditor() E.numrows = 0; E.row = NULL; E.filename = NULL; + E.statusmsg[0] = '\0'; + E.statusmsg_time = 0; if (getWindowSize(&E.screenrows, &E.screencols) == -1) { die("getWindowSize"); } - E.screenrows -= 1; + E.screenrows -= 2; } int main(int argc, char *argv[]) @@ -651,6 +684,8 @@ int main(int argc, char *argv[]) editorOpen(argv[1]); } + editorSetStatusMessage("HELP: Ctrl-Q = quit"); + while (1) { editorRefreshScreen();