2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2002-01-21 23:30:43 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2002-01-21 23:30:43 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2016-04-29 16:40:20 +03:00
|
|
|
#include "cmCursesLongMessageForm.h"
|
|
|
|
|
2001-11-30 07:45:01 +03:00
|
|
|
#include "../cmSystemTools.h"
|
2006-11-30 01:17:16 +03:00
|
|
|
#include "../cmVersion.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "../cmake.h"
|
2001-11-30 07:45:01 +03:00
|
|
|
#include "cmCursesMainForm.h"
|
|
|
|
|
2001-11-30 21:59:36 +03:00
|
|
|
inline int ctrl(int z)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return (z & 037);
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
2001-11-30 21:59:36 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCursesLongMessageForm::cmCursesLongMessageForm(
|
|
|
|
std::vector<std::string> const& messages, const char* title)
|
2001-11-30 07:45:01 +03:00
|
|
|
{
|
|
|
|
// Append all messages into on big string
|
2001-11-30 18:40:41 +03:00
|
|
|
std::vector<std::string>::const_iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = messages.begin(); it != messages.end(); it++) {
|
2006-03-16 18:44:55 +03:00
|
|
|
this->Messages += (*it);
|
2001-11-30 07:45:01 +03:00
|
|
|
// Add one blank line after each message
|
2006-03-16 18:44:55 +03:00
|
|
|
this->Messages += "\n\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-16 18:44:55 +03:00
|
|
|
this->Title = title;
|
|
|
|
this->Fields[0] = 0;
|
|
|
|
this->Fields[1] = 0;
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCursesLongMessageForm::~cmCursesLongMessageForm()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Fields[0]) {
|
2006-03-16 18:44:55 +03:00
|
|
|
free_field(this->Fields[0]);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesLongMessageForm::UpdateStatusBar()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
int x, y;
|
2001-11-30 07:45:01 +03:00
|
|
|
getmaxyx(stdscr, y, x);
|
|
|
|
|
|
|
|
char bar[cmCursesMainForm::MAX_WIDTH];
|
2010-06-29 17:52:12 +04:00
|
|
|
size_t size = strlen(this->Title.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (size >= cmCursesMainForm::MAX_WIDTH) {
|
|
|
|
size = cmCursesMainForm::MAX_WIDTH - 1;
|
|
|
|
}
|
2006-03-16 18:44:55 +03:00
|
|
|
strncpy(bar, this->Title.c_str(), size);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = size - 1; i < cmCursesMainForm::MAX_WIDTH; i++)
|
|
|
|
bar[i] = ' ';
|
2001-11-30 07:45:01 +03:00
|
|
|
|
|
|
|
int width;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (x < cmCursesMainForm::MAX_WIDTH) {
|
2001-11-30 07:45:01 +03:00
|
|
|
width = x;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
width = cmCursesMainForm::MAX_WIDTH - 1;
|
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
|
|
|
|
bar[width] = '\0';
|
|
|
|
|
|
|
|
char version[cmCursesMainForm::MAX_WIDTH];
|
|
|
|
char vertmp[128];
|
2016-05-16 17:34:04 +03:00
|
|
|
sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion());
|
|
|
|
size_t sideSpace = (width - strlen(vertmp));
|
|
|
|
for (size_t i = 0; i < sideSpace; i++) {
|
|
|
|
version[i] = ' ';
|
|
|
|
}
|
|
|
|
sprintf(version + sideSpace, "%s", vertmp);
|
2001-11-30 07:45:01 +03:00
|
|
|
version[width] = '\0';
|
|
|
|
|
2015-09-12 17:35:36 +03:00
|
|
|
char fmt_s[] = "%s";
|
2016-05-16 17:34:04 +03:00
|
|
|
curses_move(y - 4, 0);
|
2001-11-30 07:45:01 +03:00
|
|
|
attron(A_STANDOUT);
|
2015-09-12 17:35:36 +03:00
|
|
|
printw(fmt_s, bar);
|
2012-08-13 21:42:58 +04:00
|
|
|
attroff(A_STANDOUT);
|
2016-05-16 17:34:04 +03:00
|
|
|
curses_move(y - 3, 0);
|
2015-09-12 17:35:36 +03:00
|
|
|
printw(fmt_s, version);
|
2006-03-16 18:44:55 +03:00
|
|
|
pos_form_cursor(this->Form);
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesLongMessageForm::PrintKeys()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
int x, y;
|
2001-11-30 07:45:01 +03:00
|
|
|
getmaxyx(stdscr, y, x);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
|
2001-11-30 07:45:01 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
char firstLine[512];
|
2016-05-16 17:34:04 +03:00
|
|
|
sprintf(firstLine, "Press [e] to exit help");
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2015-09-12 17:35:36 +03:00
|
|
|
char fmt_s[] = "%s";
|
2016-05-16 17:34:04 +03:00
|
|
|
curses_move(y - 2, 0);
|
2015-09-12 17:35:36 +03:00
|
|
|
printw(fmt_s, firstLine);
|
2006-03-16 18:44:55 +03:00
|
|
|
pos_form_cursor(this->Form);
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|
|
|
|
|
2002-06-19 01:20:07 +04:00
|
|
|
void cmCursesLongMessageForm::Render(int, int, int, int)
|
2001-11-30 07:45:01 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
int x, y;
|
2001-11-30 07:45:01 +03:00
|
|
|
getmaxyx(stdscr, y, x);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Form) {
|
2006-03-16 18:44:55 +03:00
|
|
|
unpost_form(this->Form);
|
|
|
|
free_form(this->Form);
|
|
|
|
this->Form = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2006-03-16 18:44:55 +03:00
|
|
|
const char* msg = this->Messages.c_str();
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2001-11-30 19:34:13 +03:00
|
|
|
curses_clear();
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Fields[0]) {
|
2006-03-16 18:44:55 +03:00
|
|
|
free_field(this->Fields[0]);
|
|
|
|
this->Fields[0] = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Fields[0] = new_field(y - 6, x - 2, 1, 1, 0, 0);
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
field_opts_off(this->Fields[0], O_STATIC);
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2006-03-16 18:44:55 +03:00
|
|
|
this->Form = new_form(this->Fields);
|
|
|
|
post_form(this->Form);
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
int i = 0;
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_BEG_FIELD);
|
2016-05-16 17:34:04 +03:00
|
|
|
while (msg[i] != '\0' && i < 60000) {
|
|
|
|
if (msg[i] == '\n' && msg[i + 1] != '\0') {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_NEW_LINE);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, msg[i]);
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
i++;
|
|
|
|
}
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_BEG_FIELD);
|
2001-11-30 07:45:01 +03:00
|
|
|
|
|
|
|
this->UpdateStatusBar();
|
|
|
|
this->PrintKeys();
|
2012-08-13 21:42:58 +04:00
|
|
|
touchwin(stdscr);
|
2001-11-30 07:45:01 +03:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesLongMessageForm::HandleInput()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Form) {
|
2001-11-30 07:45:01 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
|
2001-12-04 19:16:04 +03:00
|
|
|
char debugMessage[128];
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (;;) {
|
2001-11-30 07:45:01 +03:00
|
|
|
int key = getch();
|
|
|
|
|
2001-12-04 19:16:04 +03:00
|
|
|
sprintf(debugMessage, "Message widget handling input, key: %d", key);
|
|
|
|
cmCursesForm::LogMessage(debugMessage);
|
|
|
|
|
2001-11-30 07:45:01 +03:00
|
|
|
// quit
|
2016-05-16 17:34:04 +03:00
|
|
|
if (key == 'o' || key == 'e') {
|
2001-11-30 07:45:01 +03:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == KEY_DOWN || key == ctrl('n')) {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_SCR_FLINE);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == KEY_UP || key == ctrl('p')) {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_SCR_BLINE);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == KEY_NPAGE || key == ctrl('d')) {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_SCR_FPAGE);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == KEY_PPAGE || key == ctrl('u')) {
|
2006-03-16 18:44:55 +03:00
|
|
|
form_driver(this->Form, REQ_SCR_BPAGE);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
|
|
|
|
this->UpdateStatusBar();
|
|
|
|
this->PrintKeys();
|
2012-08-13 21:42:58 +04:00
|
|
|
touchwin(stdscr);
|
|
|
|
wrefresh(stdscr);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-30 07:45:01 +03:00
|
|
|
}
|