tShow status message that appears after first keypress after timeout of 5 s - ve - a minimal text editor (work in progress) (HTM) git clone git://src.adamsgaard.dk/ve (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 4c6ac8b9eea3b516a5c0f7452d1b2fe4d1aa882f (DIR) parent 8ce8f682e8b6e18b5b095a372c929090036ea07b (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Tue, 6 Aug 2019 15:01:39 +0200 Show status message that appears after first keypress after timeout of 5 s Diffstat: M main.c | 3 +++ M output.c | 16 ++++++++++++++++ M output.h | 1 + M terminal.c | 3 ++- 4 files changed, 22 insertions(+), 1 deletion(-) --- (DIR) diff --git a/main.c b/main.c t@@ -2,6 +2,7 @@ #include "output.h" #include "input.h" #include "io.h" +#include "output.h" int main(int argc, char* argv[]) t@@ -13,6 +14,8 @@ main(int argc, char* argv[]) file_open(argv[1]); } + editor_set_status_message("HELP: Ctrl-q to quit"); + while (1) { editor_refresh_screen(); editor_process_keypress(); (DIR) diff --git a/output.c b/output.c t@@ -71,6 +71,21 @@ editor_draw_status(struct abuf *ab) ab_append(ab, " ", 1); ab_append(ab, right_status, right_status_len); } + ab_append(ab, "\x1b[m", 3); + ab_append(ab, "\r\n", 2); +} + +/* draw status message if as long as it is specified and it is not too old */ +void +editor_draw_status_message(struct abuf *ab) +{ + int msglen; + ab_append(ab, "\x1b[K", 3); + msglen = strlen(E.status_msg); + if (msglen > E.screen_columns) + msglen = E.screen_columns; + if (msglen && time(NULL) - E.status_msg_time < 5) + ab_append(ab, E.status_msg, msglen); } /* navigate over tab-representative string as one character */ t@@ -148,6 +163,7 @@ editor_refresh_screen() editor_draw_rows(&ab); editor_draw_status(&ab); + editor_draw_status_message(&ab); char buf[32]; snprintf(buf, sizeof(buf), "\x1b[%d;%dH", (DIR) diff --git a/output.h b/output.h t@@ -8,5 +8,6 @@ struct abuf { #define ABUF_INIT {NULL, 0} void editor_refresh_screen(); +void editor_set_status_message(const char *fmt, ...); #endif (DIR) diff --git a/terminal.c b/terminal.c t@@ -123,5 +123,6 @@ init_editor() { if (get_window_size(&E.screen_rows, &E.screen_columns) == -1) die("get_window_size"); - E.screen_rows -= 1; + /* E.screen_rows -= 1; */ + E.screen_rows -= 2; }