From b97c12babbc87324b8005cf7e81640e1f3c0ecf6 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 14 Jan 2022 17:30:04 +0100 Subject: ccmake: Refactor resizing logic into cmCursesForm --- Source/CursesDialog/ccmake.cxx | 19 +------------------ Source/CursesDialog/cmCursesForm.cxx | 22 ++++++++++++++++++++++ Source/CursesDialog/cmCursesForm.h | 4 ++++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index ae4c0f6..5661144 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -9,8 +9,6 @@ #include #include -#include - #include "cmsys/Encoding.hxx" #include "cmCursesColor.h" @@ -58,22 +56,7 @@ extern "C" { static void onsig(int /*unused*/) { if (cmCursesForm::CurrentForm) { - endwin(); - if (initscr() == nullptr) { - static const char errmsg[] = "Error: ncurses initialization failed\n"; - auto r = write(STDERR_FILENO, errmsg, sizeof(errmsg) - 1); - static_cast(r); - exit(1); - } - noecho(); /* Echo off */ - cbreak(); /* nl- or cr not needed */ - keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ - refresh(); - int x; - int y; - getmaxyx(stdscr, y, x); - cmCursesForm::CurrentForm->Render(1, 1, x, y); - cmCursesForm::CurrentForm->UpdateStatusBar(); + cmCursesForm::CurrentForm->HandleResize(); } signal(SIGWINCH, onsig); } diff --git a/Source/CursesDialog/cmCursesForm.cxx b/Source/CursesDialog/cmCursesForm.cxx index bd65c4a..0c32964 100644 --- a/Source/CursesDialog/cmCursesForm.cxx +++ b/Source/CursesDialog/cmCursesForm.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCursesForm.h" +#include + cmsys::ofstream cmCursesForm::DebugFile; bool cmCursesForm::Debug = false; @@ -43,3 +45,23 @@ void cmCursesForm::LogMessage(const char* msg) cmCursesForm::DebugFile << msg << std::endl; } + +void cmCursesForm::HandleResize() +{ + endwin(); + if (initscr() == nullptr) { + static const char errmsg[] = "Error: ncurses initialization failed\n"; + auto r = write(STDERR_FILENO, errmsg, sizeof(errmsg) - 1); + static_cast(r); + exit(1); + } + noecho(); /* Echo off */ + cbreak(); /* nl- or cr not needed */ + keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ + refresh(); + int x; + int y; + getmaxyx(stdscr, y, x); + this->Render(1, 1, x, y); + this->UpdateStatusBar(); +} diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h index 93459b9..3a1eb25 100644 --- a/Source/CursesDialog/cmCursesForm.h +++ b/Source/CursesDialog/cmCursesForm.h @@ -55,6 +55,10 @@ public: static cmCursesForm* CurrentForm; + // Description: + // Handle resizing the form with curses. + void HandleResize(); + protected: static cmsys::ofstream DebugFile; static bool Debug; -- cgit v0.12