tOnly reserve space for status message when one is shown - 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 311ae0367363d872bbfa79140b23a515b28661c1
 (DIR) parent 4c6ac8b9eea3b516a5c0f7452d1b2fe4d1aa882f
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Tue,  6 Aug 2019 15:34:49 +0200
       
       Only reserve space for status message when one is shown
       
       Diffstat:
         M byote.h                             |       2 ++
         M main.c                              |       4 +++-
         M output.c                            |      31 ++++++++++++++++++++++++++++---
         M terminal.c                          |       4 ++--
       
       4 files changed, 35 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/byote.h b/byote.h
       t@@ -8,6 +8,7 @@
        #define VERSION "0.0.1"
        
        #define TAB_WIDTH 4
       +#define STATUS_MESSAGE_TIMEOUT 3
        
        /* editor row: stores a row of text */
        typedef struct eRow {
       t@@ -26,6 +27,7 @@ struct editor_config {
                char *filename;
                struct termios orig_termios;
                int mode; /* 0: normal, 1: insert, 2: visual */
       +        int show_status;
                char status_msg[80];
                time_t status_msg_time;
        };
 (DIR) diff --git a/main.c b/main.c
       t@@ -3,6 +3,7 @@
        #include "input.h"
        #include "io.h"
        #include "output.h"
       +#include "byote.h"
        
        int
        main(int argc, char* argv[])
       t@@ -10,11 +11,12 @@ main(int argc, char* argv[])
                enable_raw_mode();
                init_editor();
        
       +        /* TODO: proper argument handling */
                if (argc >= 2) {
                        file_open(argv[1]);
                }
        
       -        editor_set_status_message("HELP: Ctrl-q to quit");
       +        editor_set_status_message("-- %s v%s --", PROGNAME, VERSION);
        
                while (1) {
                        editor_refresh_screen();
 (DIR) diff --git a/output.c b/output.c
       t@@ -27,6 +27,23 @@ ab_free(struct abuf *ab) {
                free(ab->b);
        }
        
       +int
       +show_status_message()
       +{
       +        /* TODO try simpler form */
       +        if (E.show_status &&
       +            strlen(E.status_msg) &&
       +            time(NULL) - E.status_msg_time < STATUS_MESSAGE_TIMEOUT) {
       +                return 1;
       +        } else {
       +                if (E.show_status) {
       +                        E.show_status = 0;
       +                        E.screen_rows++;
       +                }
       +                return 0;
       +        }
       +}
       +
        /* draw status line consisting of left and right components.
         * if the screen is narrower than both parts, just show the left status, 
         * truncated, if necessary. */
       t@@ -71,8 +88,11 @@ 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);
       +
       +        if (show_status_message()) {
       +                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 */
       t@@ -84,7 +104,7 @@ editor_draw_status_message(struct abuf *ab)
                msglen = strlen(E.status_msg);
                if (msglen > E.screen_columns)
                        msglen = E.screen_columns;
       -        if (msglen && time(NULL) - E.status_msg_time < 5)
       +        if (show_status_message())
                        ab_append(ab, E.status_msg, msglen);
        }
        
       t@@ -186,4 +206,9 @@ editor_set_status_message(const char *fmt, ...)
                vsnprintf(E.status_msg, sizeof(E.status_msg), fmt, ap);
                va_end(ap);
                E.status_msg_time = time(NULL);
       +
       +        if (!E.show_status) {
       +                E.screen_rows--;
       +                E.show_status = 1;
       +        }
        }
 (DIR) diff --git a/terminal.c b/terminal.c
       t@@ -120,9 +120,9 @@ init_editor() {
                E.filename = NULL;
                E.status_msg[0] = '\0';
                E.status_msg_time = 0;
       +        E.show_status = 0;
        
                if (get_window_size(&E.screen_rows, &E.screen_columns) == -1)
                        die("get_window_size");
       -        /* E.screen_rows -= 1; */
       -        E.screen_rows -= 2;
       +        E.screen_rows -= 1;
        }