summaryrefslogtreecommitdiffstats
path: root/Source/CursesDialog/cmCursesMainForm.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CursesDialog/cmCursesMainForm.cxx')
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx271
1 files changed, 128 insertions, 143 deletions
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 6b71e8a..2c92835 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -34,6 +34,7 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
: Args(std::move(args))
, InitialWidth(initWidth)
{
+ this->HasNonStatusOutputs = false;
this->NumberOfPages = 0;
this->AdvancedMode = false;
this->NumberOfVisibleEntries = 0;
@@ -321,25 +322,25 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
} else {
if (this->OkToGenerate) {
sprintf(firstLine,
- "Press [c] to configure Press [g] to generate and exit");
+ " [l] Show log output [c] Configure"
+ " [g] Generate ");
} else {
sprintf(firstLine,
- "Press [c] to configure ");
+ " [l] Show log output [c] Configure"
+ " ");
}
{
const char* toggleKeyInstruction =
- "Press [t] to toggle advanced mode (Currently %s)";
+ " [t] Toggle advanced mode (currently %s)";
sprintf(thirdLine, toggleKeyInstruction,
- this->AdvancedMode ? "On" : "Off");
+ this->AdvancedMode ? "on" : "off");
}
sprintf(secondLine,
- "Press [h] for help "
- "Press [q] to quit without generating");
+ " [h] Help [q] Quit without generating");
}
curses_move(y - 4, 0);
- char fmt[512] =
- "Press [enter] to edit option Press [d] to delete an entry";
+ char fmt[512] = "Keys: [enter] Edit an entry [d] Delete an entry";
if (process) {
memset(fmt, ' ', 57);
}
@@ -364,7 +365,7 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
// Print the key of the current entry and the CMake version
// on the status bar. Designed for a width of 80 chars.
-void cmCursesMainForm::UpdateStatusBar(const char* message)
+void cmCursesMainForm::UpdateStatusBar(cm::optional<std::string> message)
{
int x;
int y;
@@ -385,119 +386,91 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
return;
}
- // Get the key of the current entry
- FIELD* cur = current_field(this->Form);
- int findex = field_index(cur);
- cmCursesWidget* lbl = nullptr;
- if (findex >= 0) {
- lbl = reinterpret_cast<cmCursesWidget*>(
- field_userptr(this->Fields[findex - 2]));
- }
- char help[128] = "";
- const char* curField = "";
- if (lbl) {
- curField = lbl->GetValue();
+ // Find the current label index
+ // Field are grouped by 3, the label should be 2 less than the current index
+ using size_type = decltype(this->Fields)::size_type;
+ size_type currentLabelIndex = field_index(current_field(this->Form)) - 2;
+
+ // Use the status message if any, otherwise join the key and help string
+ std::string bar;
+ if (message) {
+ bar = *message;
+ } else {
+ // Get the key of the current entry
+ cmCursesWidget* labelWidget = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[currentLabelIndex]));
+ std::string labelValue = labelWidget->GetValue();
+ bar = labelValue + ": ";
// Get the help string of the current entry
// and add it to the help string
- const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
+ auto cmakeState = this->CMakeInstance->GetState();
+ const char* existingValue = cmakeState->GetCacheEntryValue(labelValue);
if (existingValue) {
- const char* hs = this->CMakeInstance->GetState()->GetCacheEntryProperty(
- curField, "HELPSTRING");
- if (hs) {
- strncpy(help, hs, 127);
- help[127] = '\0';
- } else {
- help[0] = 0;
+ auto help = cmakeState->GetCacheEntryProperty(labelValue, "HELPSTRING");
+ if (help) {
+ bar += help;
}
- } else {
- sprintf(help, " ");
}
}
+ // Pad with spaces to erase any previous text,
+ // or truncate as necessary to fit the screen
+ bar.resize(x, ' ');
+ curses_move(y - 5, 0);
+ attron(A_STANDOUT);
+ char fmt_s[] = "%s";
+ printw(fmt_s, bar.c_str());
+ attroff(A_STANDOUT);
- // Join the key, help string and pad with spaces
- // (or truncate) as necessary
- char bar[cmCursesMainForm::MAX_WIDTH];
- size_t curFieldLen = strlen(curField);
- size_t helpLen = strlen(help);
-
- size_t width = std::min<size_t>(x, cmCursesMainForm::MAX_WIDTH);
-
- if (message) {
- curField = message;
- curFieldLen = strlen(message);
- strncpy(bar, curField, width);
- if (curFieldLen < width) {
- memset(bar + curFieldLen, ' ', width - curFieldLen);
- }
- } else {
- strncpy(bar, curField, width);
- if (curFieldLen < width) {
- bar[curFieldLen] = ':';
- bar[curFieldLen + 1] = ' ';
- strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2);
- if (curFieldLen + helpLen + 2 < width) {
- memset(bar + curFieldLen + helpLen + 2, ' ',
- width - (curFieldLen + helpLen + 2));
- }
- }
+ // Highlight the current label, reset others
+ // Fields are grouped by 3, the first one being the label
+ // so start at 0 and move up by 3 avoiding the last null entry
+ for (size_type index = 0; index < this->Fields.size() - 1; index += 3) {
+ bool currentLabel = index == currentLabelIndex;
+ set_field_fore(this->Fields[index], currentLabel ? A_STANDOUT : A_NORMAL);
}
- bar[width] = '\0';
-
- // Display CMake version info on the next line
+ // Display CMake version under the status bar
// We want to display this on the right
- char version[cmCursesMainForm::MAX_WIDTH];
- char vertmp[128];
- sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion());
- size_t sideSpace = (width - strlen(vertmp));
- memset(version, ' ', sideSpace);
- sprintf(version + sideSpace, "%s", vertmp);
- version[width] = '\0';
-
- // Now print both lines
- char fmt_s[] = "%s";
- curses_move(y - 5, 0);
- attron(A_STANDOUT);
- printw(fmt_s, bar);
- attroff(A_STANDOUT);
- curses_move(y - 4, 0);
- printw(fmt_s, version);
+ std::string version = "CMake Version ";
+ version += cmVersion::GetCMakeVersion();
+ version.resize(std::min<std::string::size_type>(x, version.size()));
+ curses_move(y - 4, x - static_cast<int>(version.size()));
+ printw(fmt_s, version.c_str());
+
pos_form_cursor(this->Form);
}
void cmCursesMainForm::UpdateProgress(const std::string& msg, float prog)
{
- char tmp[1024];
- const char* cmsg = tmp;
if (prog >= 0) {
- sprintf(tmp, "%s %i%%", msg.c_str(), static_cast<int>(100 * prog));
+ constexpr int progressBarWidth = 40;
+ int progressBarCompleted = static_cast<int>(progressBarWidth * prog);
+ int percentCompleted = static_cast<int>(100 * prog);
+ this->LastProgress = (percentCompleted < 100 ? " " : "");
+ this->LastProgress += (percentCompleted < 10 ? " " : "");
+ this->LastProgress += std::to_string(percentCompleted) + "% [";
+ this->LastProgress.append(progressBarCompleted, '#');
+ this->LastProgress.append(progressBarWidth - progressBarCompleted, ' ');
+ this->LastProgress += "] " + msg + "...";
} else {
- cmsg = msg.c_str();
+ this->Outputs.emplace_back(msg);
}
- this->UpdateStatusBar(cmsg);
- this->PrintKeys(1);
- curses_move(1, 1);
- touchwin(stdscr);
- refresh();
+
+ this->DisplayOutputs();
}
int cmCursesMainForm::Configure(int noconfigure)
{
- int xi;
- int yi;
- getmaxyx(stdscr, yi, xi);
-
- curses_move(1, 1);
- this->UpdateStatusBar("Configuring, please wait...");
- this->PrintKeys(1);
- touchwin(stdscr);
- refresh();
- this->CMakeInstance->SetProgressCallback(
- [this](const std::string& msg, float prog) {
- this->UpdateProgress(msg, prog);
- });
+ this->ResetOutputs();
+
+ if (noconfigure == 0) {
+ this->UpdateProgress("Configuring", 0);
+ this->CMakeInstance->SetProgressCallback(
+ [this](const std::string& msg, float prog) {
+ this->UpdateProgress(msg, prog);
+ });
+ }
// always save the current gui values to disk
this->FillCacheManagerFromUI();
@@ -505,9 +478,6 @@ int cmCursesMainForm::Configure(int noconfigure)
this->CMakeInstance->GetHomeOutputDirectory());
this->LoadCache(nullptr);
- // Get rid of previous errors
- this->Errors = std::vector<std::string>();
-
// run the generate process
this->OkToGenerate = true;
int retVal;
@@ -524,7 +494,7 @@ int cmCursesMainForm::Configure(int noconfigure)
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
- if (retVal != 0 || !this->Errors.empty()) {
+ if (retVal != 0 || this->HasNonStatusOutputs) {
// see if there was an error
if (cmSystemTools::GetErrorOccuredFlag()) {
this->OkToGenerate = false;
@@ -532,11 +502,13 @@ int cmCursesMainForm::Configure(int noconfigure)
int xx;
int yy;
getmaxyx(stdscr, yy, xx);
- cmCursesLongMessageForm* msgs =
- new cmCursesLongMessageForm(this->Errors,
- cmSystemTools::GetErrorOccuredFlag()
- ? "Errors occurred during the last pass."
- : "CMake produced the following output.");
+ const char* title = "Configure produced the following output";
+ if (cmSystemTools::GetErrorOccuredFlag()) {
+ title = "Configure failed with the following output";
+ }
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
+ this->Outputs, title,
+ cmCursesLongMessageForm::ScrollBehavior::ScrollDown);
// reset error condition
cmSystemTools::ResetErrorOccuredFlag();
CurrentForm = msgs;
@@ -547,11 +519,13 @@ int cmCursesMainForm::Configure(int noconfigure)
if (retVal == -2) {
return retVal;
}
- CurrentForm = this;
- this->Render(1, 1, xx, yy);
}
this->InitializeUI();
+ CurrentForm = this;
+ int xi;
+ int yi;
+ getmaxyx(stdscr, yi, xi);
this->Render(1, 1, xi, yi);
return 0;
@@ -559,30 +533,21 @@ int cmCursesMainForm::Configure(int noconfigure)
int cmCursesMainForm::Generate()
{
- int xi;
- int yi;
- getmaxyx(stdscr, yi, xi);
+ this->ResetOutputs();
- curses_move(1, 1);
- this->UpdateStatusBar("Generating, please wait...");
- this->PrintKeys(1);
- touchwin(stdscr);
- refresh();
+ this->UpdateProgress("Generating", 0);
this->CMakeInstance->SetProgressCallback(
[this](const std::string& msg, float prog) {
this->UpdateProgress(msg, prog);
});
- // Get rid of previous errors
- this->Errors = std::vector<std::string>();
-
// run the generate process
int retVal = this->CMakeInstance->Generate();
this->CMakeInstance->SetProgressCallback(nullptr);
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
- if (retVal != 0 || !this->Errors.empty()) {
+ if (retVal != 0 || this->HasNonStatusOutputs) {
// see if there was an error
if (cmSystemTools::GetErrorOccuredFlag()) {
this->OkToGenerate = false;
@@ -592,12 +557,13 @@ int cmCursesMainForm::Generate()
int xx;
int yy;
getmaxyx(stdscr, yy, xx);
- const char* title = "Messages during last pass.";
+ const char* title = "Generate produced the following output";
if (cmSystemTools::GetErrorOccuredFlag()) {
- title = "Errors occurred during the last pass.";
+ title = "Generate failed with the following output";
}
- cmCursesLongMessageForm* msgs =
- new cmCursesLongMessageForm(this->Errors, title);
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
+ this->Outputs, title,
+ cmCursesLongMessageForm::ScrollBehavior::ScrollDown);
CurrentForm = msgs;
msgs->Render(1, 1, xx, yy);
msgs->HandleInput();
@@ -606,11 +572,13 @@ int cmCursesMainForm::Generate()
if (retVal == -2) {
return retVal;
}
- CurrentForm = this;
- this->Render(1, 1, xx, yy);
}
this->InitializeUI();
+ CurrentForm = this;
+ int xi;
+ int yi;
+ getmaxyx(stdscr, yi, xi);
this->Render(1, 1, xi, yi);
return 0;
@@ -619,7 +587,9 @@ int cmCursesMainForm::Generate()
void cmCursesMainForm::AddError(const std::string& message,
const char* /*unused*/)
{
- this->Errors.emplace_back(message);
+ this->Outputs.emplace_back(message);
+ this->HasNonStatusOutputs = true;
+ this->DisplayOutputs();
}
void cmCursesMainForm::RemoveEntry(const char* value)
@@ -704,7 +674,7 @@ void cmCursesMainForm::HandleInput()
this->PrintKeys();
if (this->SearchMode) {
std::string searchstr = "Search: " + this->SearchString;
- this->UpdateStatusBar(searchstr.c_str());
+ this->UpdateStatusBar(searchstr);
this->PrintKeys(1);
curses_move(y - 5, static_cast<unsigned int>(searchstr.size()));
// curses_move(1,1);
@@ -848,8 +818,9 @@ void cmCursesMainForm::HandleInput()
this->HelpMessage[1] = "";
}
- cmCursesLongMessageForm* msgs =
- new cmCursesLongMessageForm(this->HelpMessage, "Help.");
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
+ this->HelpMessage, "Help",
+ cmCursesLongMessageForm::ScrollBehavior::NoScroll);
CurrentForm = msgs;
msgs->Render(1, 1, x, y);
msgs->HandleInput();
@@ -861,7 +832,8 @@ void cmCursesMainForm::HandleInput()
else if (key == 'l') {
getmaxyx(stdscr, y, x);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
- this->Errors, "Errors occurred during the last pass.");
+ this->Outputs, "CMake produced the following output",
+ cmCursesLongMessageForm::ScrollBehavior::NoScroll);
CurrentForm = msgs;
msgs->Render(1, 1, x, y);
msgs->HandleInput();
@@ -1007,15 +979,6 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr)
} else {
form_driver(this->Form, REQ_NEXT_FIELD);
}
- /*
- char buffer[1024];
- sprintf(buffer, "Line: %d != %d / %d\n", findex, idx,
- this->NumberOfVisibleEntries);
- touchwin(stdscr);
- refresh();
- this->UpdateStatusBar( buffer );
- usleep(100000);
- */
cur = current_field(this->Form);
findex = field_index(cur);
if (findex == start_index) {
@@ -1024,6 +987,28 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr)
}
}
+void cmCursesMainForm::ResetOutputs()
+{
+ this->LogForm.reset();
+ this->Outputs.clear();
+ this->HasNonStatusOutputs = false;
+ this->LastProgress.clear();
+}
+
+void cmCursesMainForm::DisplayOutputs()
+{
+ int xi;
+ int yi;
+ getmaxyx(stdscr, yi, xi);
+
+ auto newLogForm = new cmCursesLongMessageForm(
+ this->Outputs, this->LastProgress.c_str(),
+ cmCursesLongMessageForm::ScrollBehavior::ScrollDown);
+ CurrentForm = newLogForm;
+ this->LogForm.reset(newLogForm);
+ this->LogForm->Render(1, 1, xi, yi);
+}
+
const char* cmCursesMainForm::s_ConstHelpMessage =
"CMake is used to configure and generate build files for software projects. "
"The basic steps for configuring a project with ccmake are as follows:\n\n"
@@ -1080,7 +1065,7 @@ const char* cmCursesMainForm::s_ConstHelpMessage =
" c : process the configuration files with the current options\n"
" g : generate build files and exit, only available when there are no "
"new options and no errors have been detected during last configuration.\n"
- " l : shows last errors\n"
+ " l : shows cmake output\n"
" d : delete an option\n"
" t : toggles advanced mode. In normal mode, only the most important "
"options are shown. In advanced mode, all options are shown. We recommend "