cmake/Source/CursesDialog/cmCursesForm.cxx

75 lines
1.5 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesForm.h"
2022-03-29 21:10:50 +02:00
#include <cstdlib>
#ifndef _WIN32
# include <unistd.h>
#endif // _WIN32
2014-08-03 19:52:23 +02:00
cmsys::ofstream cmCursesForm::DebugFile;
bool cmCursesForm::Debug = false;
cmCursesForm::cmCursesForm()
{
2018-01-26 17:06:56 +01:00
this->Form = nullptr;
}
cmCursesForm::~cmCursesForm()
{
2016-07-09 11:21:54 +02:00
if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
2018-01-26 17:06:56 +01:00
this->Form = nullptr;
2016-07-09 11:21:54 +02:00
}
}
void cmCursesForm::DebugStart()
{
cmCursesForm::Debug = true;
cmCursesForm::DebugFile.open("ccmakelog.txt");
}
void cmCursesForm::DebugEnd()
{
2016-07-09 11:21:54 +02:00
if (!cmCursesForm::Debug) {
return;
2016-07-09 11:21:54 +02:00
}
cmCursesForm::Debug = false;
cmCursesForm::DebugFile.close();
}
void cmCursesForm::LogMessage(const char* msg)
{
2016-07-09 11:21:54 +02:00
if (!cmCursesForm::Debug) {
return;
2016-07-09 11:21:54 +02:00
}
cmCursesForm::DebugFile << msg << std::endl;
}
2022-03-29 21:10:50 +02:00
void cmCursesForm::HandleResize()
{
endwin();
if (initscr() == nullptr) {
static const char errmsg[] = "Error: ncurses initialization failed\n";
#ifdef _WIN32
fprintf(stderr, "%s", errmsg);
#else
auto r = write(STDERR_FILENO, errmsg, sizeof(errmsg) - 1);
static_cast<void>(r);
#endif // _WIN32
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();
}