From 3300070cc2e7cadcb0fe2a77d67d2099bf22e7ba Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Wed, 23 Oct 2019 16:32:31 +0200 Subject: ccmake: Display an ASCII progress bar in the status bar The status bar is now only used to display the progress. The status log are not shown anymore since for the most cases they went by too quickly to be read. As for cases when a process is long enough to display and read a log, it would probably be a previous unrelated message. --- Source/CursesDialog/cmCursesMainForm.cxx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 6b71e8a..3f7ee89 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -469,14 +469,18 @@ void cmCursesMainForm::UpdateStatusBar(const char* message) 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(100 * prog)); - } else { - cmsg = msg.c_str(); + constexpr int progressBarWidth = 40; + int progressBarCompleted = static_cast(progressBarWidth * prog); + int percentCompleted = static_cast(100 * prog); + std::string status = (percentCompleted < 100 ? " " : ""); + status += (percentCompleted < 10 ? " " : ""); + status += std::to_string(percentCompleted) + "% ["; + status.append(progressBarCompleted, '#'); + status.append(progressBarWidth - progressBarCompleted, ' '); + status += "] " + msg + "..."; + this->UpdateStatusBar(status.c_str()); } - this->UpdateStatusBar(cmsg); this->PrintKeys(1); curses_move(1, 1); touchwin(stdscr); @@ -489,11 +493,7 @@ int cmCursesMainForm::Configure(int noconfigure) int yi; getmaxyx(stdscr, yi, xi); - curses_move(1, 1); - this->UpdateStatusBar("Configuring, please wait..."); - this->PrintKeys(1); - touchwin(stdscr); - refresh(); + this->UpdateProgress("Configuring", 0); this->CMakeInstance->SetProgressCallback( [this](const std::string& msg, float prog) { this->UpdateProgress(msg, prog); @@ -563,11 +563,7 @@ int cmCursesMainForm::Generate() int yi; getmaxyx(stdscr, yi, xi); - 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); -- cgit v0.12