From 091a63a6793d46124d7453ddbc3cc0dd9bfb731b Mon Sep 17 00:00:00 2001 From: gunboy001 Date: Mon, 9 Dec 2019 17:45:07 +0100 Subject: [PATCH] status info now updates correctly --- src/config.h | 5 +++++ src/ste.c | 15 +++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/config.h b/src/config.h index e396add..0fab92b 100644 --- a/src/config.h +++ b/src/config.h @@ -18,4 +18,9 @@ #define KEY_MOVE_DOWN KEY_DOWN #define KEY_FILE_FIND CTRL('f') +/* Modify ONLY if you know what you are doing */ +#define FILENAME_MAX_LENGTH 128 +#define STAT_SIZE 256 +/*--------------------------------------------*/ + #endif diff --git a/src/ste.c b/src/ste.c index 2ca7251..88d9dac 100644 --- a/src/ste.c +++ b/src/ste.c @@ -14,7 +14,6 @@ /* defines */ #define CTRL(k) ((k) & 0x1f) // Control mask modifier -#define STAT_SIZE 128 #define CBUF_SIZE 2048 #define MODE_MASK 0x1 @@ -59,6 +58,7 @@ struct term { int pad; char mode_b; CharBuffer search_buffer; + char filename[FILENAME_MAX_LENGTH]; } t; FileBuffer rows; @@ -106,18 +106,14 @@ int main (int argc, char *argv[]) bufInit(&rows); /* Try to open the file */ - if (argc < 2) { - perror("File not found"); - exit(1); - } else fileOpen(argv[1]); + if (argc < 2) die("File not found", BAD_FILE); + fileOpen(argv[1]); + snprintf(t.filename, FILENAME_MAX_LENGTH, "%s", argv[1]); /* Initialize the terminal in raw mode, * start curses and initialize the term struct */ termInit(); - /* Set the statusbar left (static) message */ - snprintf(t.statusbar, STAT_SIZE, "%s %d lines %dx%d", argv[1], rows.rownum, t.dim.y, t.dim.x); - /* Main event loop */ while (1) { static int c; @@ -574,6 +570,9 @@ void handleDel (int select) void updateInfo (void) { + /* Set the statusbar left message */ + snprintf(t.statusbar, STAT_SIZE, "%s %d lines %dx%d", t.filename, rows.rownum, t.dim.y, t.dim.x); + getmaxyx(stdscr, t.dim.y, t.dim.x); t.dim.y -= 1; t.pad = decimalSize(rows.rownum - 1);