From df5022e383e931ae8ad6f41e775c18cfbb2ed80b Mon Sep 17 00:00:00 2001 From: Tobias Boege Date: Mon, 4 Jan 2021 17:16:23 +0100 Subject: [PATCH] gb.ncurses: allow stepping out of and into ncurses mode [GB.NCURSES] * NEW: Screen.Suspend and Screen.Resume are two new methods which allow to temporarily leave ncurses mode, restoring the original tty settings, and to come back, restoring ncurses's tty settings and screen content. --- gb.ncurses/src/c_screen.c | 21 +++++++++++++++++++++ gb.ncurses/src/c_screen.h | 1 + 2 files changed, 22 insertions(+) diff --git a/gb.ncurses/src/c_screen.c b/gb.ncurses/src/c_screen.c index eac2df773..7ba90ccdc 100644 --- a/gb.ncurses/src/c_screen.c +++ b/gb.ncurses/src/c_screen.c @@ -68,6 +68,8 @@ void SCREEN_refresh() { if (!NCURSES_RUNNING) return; + if (THIS->suspended) + return; update_panels(); doupdate(); } @@ -99,6 +101,7 @@ static void CSCREEN_echo(CSCREEN *scr, int mode) BEGIN_METHOD_VOID(Screen_new) + THIS->suspended = 0; CSCREEN_cursor(THIS, 1); CSCREEN_echo(THIS, 1); INPUT_mode(THIS, INPUT_CBREAK); @@ -182,6 +185,21 @@ BEGIN_METHOD(Screen_Resize, GB_INTEGER lines; GB_INTEGER cols) END_METHOD +BEGIN_METHOD_VOID(Screen_Suspend) + + THIS->suspended = 1; + def_prog_mode(); + endwin(); + +END_METHOD + +BEGIN_METHOD_VOID(Screen_Resume) + + THIS->suspended = 0; + doupdate(); + +END_METHOD + GB_DESC CCursorDesc[] = { GB_DECLARE("Cursor", 0), GB_NOT_CREATABLE(), @@ -259,6 +277,9 @@ GB_DESC CScreenDesc[] = { GB_STATIC_METHOD("Refresh", NULL, Screen_Refresh, NULL), GB_STATIC_METHOD("Resize", NULL, Screen_Resize, "(Lines)i(Cols)i"), + GB_STATIC_METHOD("Suspend", NULL, Screen_Suspend, NULL), + GB_STATIC_METHOD("Resume", NULL, Screen_Resume, NULL), + GB_STATIC_PROPERTY("Cursor", "i", Screen_Cursor), GB_STATIC_PROPERTY("Echo", "b", Screen_Echo), GB_STATIC_PROPERTY("Input", "i", Screen_Input), diff --git a/gb.ncurses/src/c_screen.h b/gb.ncurses/src/c_screen.h index 9767dc383..a3309721b 100644 --- a/gb.ncurses/src/c_screen.h +++ b/gb.ncurses/src/c_screen.h @@ -40,6 +40,7 @@ typedef struct { int cursor; int input; int buffered; + int suspended; } CSCREEN; int SCREEN_init();