1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

ccmake: Refactor resizing logic into cmCursesForm

This commit is contained in:
Duncan Ogilvie
2022-01-14 17:30:04 +01:00
committed by Brad King
parent bf11dab49d
commit b97c12babb
3 changed files with 27 additions and 18 deletions

View File

@@ -9,8 +9,6 @@
#include <string>
#include <vector>
#include <unistd.h>
#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<void>(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);
}

View File

@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesForm.h"
#include <unistd.h>
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<void>(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();
}

View File

@@ -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;