From f73dbd7d8a66cffbb2ee1a8271f0182cc40f8768 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Thu, 11 Sep 2025 19:24:48 +1000 Subject: [PATCH] ensure initscr(3x) & use newwin(3x) not stdscr(3x) for root node --- cli/curse.c | 22 ++++++++++++---------- cli/curse.h | 3 +-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cli/curse.c b/cli/curse.c index 3274239..3c465fe 100644 --- a/cli/curse.c +++ b/cli/curse.c @@ -25,6 +25,15 @@ int termmode(const enum crs_termmode mode) { } } +/* Apply a default IO configuration for an ncurses WINDOW. + */ +static inline void __conf_window(WINDOW *const win) { + nodelay(win, TRUE); // getch(3x) nonblocking IO + keypad(win, TRUE); // allow function keys + // intrflush(3x) - flush terminal input buffer on interrupt key + intrflush(win, FALSE); +} + /* Initialise ncurses for our usecase. * WARNING: This function should only be called once. */ @@ -33,6 +42,8 @@ void init_ncurses(void) { setlocale(LC_ALL, CRS_LOCALE); /* NCurses Init */ + initscr(); + __conf_window(stdscr); start_color(); /* Screen Configuration */ @@ -42,15 +53,6 @@ void init_ncurses(void) { curs_set(0); // hide cursor } -/* Apply a default IO configuration for an ncurses WINDOW. - */ -static inline void __conf_window(WINDOW *const win) { - nodelay(win, TRUE); // getch(3x) nonblocking IO - keypad(win, TRUE); // allow function keys - // intrflush(3x) - flush terminal input buffer on interrupt key - intrflush(win, FALSE); -} - /* Initialise (with default IO configuration) a new ncurses WINDOW. */ WINDOW *new_window(const int x, const int y, const int width, @@ -65,7 +67,7 @@ WINDOW *new_window(const int x, const int y, const int width, * NOTE: This is typically done via initscr(3x) and called "stdscr". */ WINDOW *root_window(void) { - WINDOW *rootwin = new_window(0, 0, 0, 0); + WINDOW *rootwin = new_window(0, 0, COLS, LINES); __conf_window(rootwin); return rootwin; } diff --git a/cli/curse.h b/cli/curse.h index 338ffe6..72f0e7e 100644 --- a/cli/curse.h +++ b/cli/curse.h @@ -18,8 +18,7 @@ enum crs_termmode { int termmode(const enum crs_termmode mode); void init_ncurses(void); -WINDOW *init_window(const int x, const int y, const int width, - const int height); +WINDOW *new_window(const int x, const int y, const int width, const int height); WINDOW *root_window(void); int resizemv_window(const int x, const int y, const int width, const int height,