Add progress to ccmake

This commit is contained in:
Andy Cedilnik 2002-11-19 13:09:16 -05:00
parent 0cb9343e83
commit 1d39833446
2 changed files with 121 additions and 58 deletions

View File

@ -353,7 +353,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
refresh(); refresh();
} }
void cmCursesMainForm::PrintKeys() void cmCursesMainForm::PrintKeys(int process /* = 0 */)
{ {
int x,y; int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
@ -381,10 +381,24 @@ void cmCursesMainForm::PrintKeys()
// } // }
// else // else
// { // {
char firstLine[512], secondLine[512], thirdLine[512]; char firstLine[512]="";
char secondLine[512]="";
char thirdLine[512]="";
if (process)
{
sprintf(firstLine,
" ");
sprintf(secondLine,
" ");
sprintf(thirdLine,
" ");
}
else
{
if (m_OkToGenerate) if (m_OkToGenerate)
{ {
sprintf(firstLine, "Press [c] to configure Press [g] to generate and exit"); sprintf(firstLine,
"Press [c] to configure Press [g] to generate and exit");
} }
else else
{ {
@ -399,25 +413,30 @@ void cmCursesMainForm::PrintKeys()
sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently Off)"); sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently Off)");
} }
sprintf(secondLine, "Press [h] for help Press [q] to quit without generating"); sprintf(secondLine,
"Press [h] for help Press [q] to quit without generating");
}
curses_move(y-4,0);
char *fmt = "Press [enter] to edit option";
if ( process )
{
fmt = " ";
}
printw(fmt);
curses_move(y-3,0);
printw(firstLine);
curses_move(y-2,0);
printw(secondLine);
curses_move(y-1,0);
printw(thirdLine);
curses_move(y-4,0); if (cw)
char fmt[] = "Press [enter] to edit option"; {
printw(fmt); sprintf(firstLine, "Page %d of %d", cw->GetPage(), m_NumberOfPages);
curses_move(y-3,0); curses_move(0,65-strlen(firstLine)-1);
printw(firstLine); printw(firstLine);
curses_move(y-2,0); }
printw(secondLine);
curses_move(y-1,0);
printw(thirdLine);
if (cw)
{
sprintf(firstLine, "Page %d of %d", cw->GetPage(), m_NumberOfPages);
curses_move(0,65-strlen(firstLine)-1);
printw(firstLine);
}
// } // }
pos_form_cursor(m_Form); pos_form_cursor(m_Form);
@ -426,7 +445,7 @@ void cmCursesMainForm::PrintKeys()
// Print the key of the current entry and the CMake version // Print the key of the current entry and the CMake version
// on the status bar. Designed for a width of 80 chars. // on the status bar. Designed for a width of 80 chars.
void cmCursesMainForm::UpdateStatusBar() void cmCursesMainForm::UpdateStatusBar(const char* message)
{ {
int x,y; int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
@ -500,32 +519,54 @@ void cmCursesMainForm::UpdateStatusBar()
width = cmCursesMainForm::MAX_WIDTH; width = cmCursesMainForm::MAX_WIDTH;
} }
if (curFieldLen >= width) if ( message )
{ {
strncpy(bar, curField, width); curField = message;
} curFieldLen = strlen(message);
else if ( curFieldLen < width )
{
strcpy(bar, curField);
bar[curFieldLen] = ':';
bar[curFieldLen+1] = ' ';
if (curFieldLen + helpLen + 2 >= width)
{ {
strncpy(bar+curFieldLen+2, help, width strcpy(bar, curField);
- curFieldLen - 2); for(i=curFieldLen; i < width; ++i)
}
else
{
strcpy(bar+curFieldLen+2, help);
for(i=curFieldLen+helpLen+2; i < width; ++i)
{ {
bar[i] = ' '; bar[i] = ' ';
} }
} }
else
{
strncpy(bar, curField, width);
}
}
else
{
if (curFieldLen >= width)
{
strncpy(bar, curField, width);
}
else
{
strcpy(bar, curField);
bar[curFieldLen] = ':';
bar[curFieldLen+1] = ' ';
if (curFieldLen + helpLen + 2 >= width)
{
strncpy(bar+curFieldLen+2, help, width
- curFieldLen - 2);
}
else
{
strcpy(bar+curFieldLen+2, help);
for(i=curFieldLen+helpLen+2; i < width; ++i)
{
bar[i] = ' ';
}
}
}
} }
bar[width] = '\0'; bar[width] = '\0';
// Display CMake version info on the next line // Display CMake version info on the next line
// We want to display this on the right // We want to display this on the right
char version[cmCursesMainForm::MAX_WIDTH]; char version[cmCursesMainForm::MAX_WIDTH];
@ -540,14 +581,14 @@ void cmCursesMainForm::UpdateStatusBar()
// Now print both lines // Now print both lines
curses_move(y-5,0); curses_move(y-5,0);
attron(A_STANDOUT); attron(A_STANDOUT);
printw(bar); printw("%s", bar);
attroff(A_STANDOUT); attroff(A_STANDOUT);
curses_move(y-4,0); curses_move(y-4,0);
printw(version); printw(version);
pos_form_cursor(m_Form); pos_form_cursor(m_Form);
} }
void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void*) void cmCursesMainForm::UpdateProgressOld(const char *msg, float prog, void*)
{ {
if ( prog < 0 ) if ( prog < 0 )
{ {
@ -555,18 +596,41 @@ void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void*)
} }
} }
void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void* vp)
{
cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp);
if ( !cm )
{
return;
}
char tmp[1024];
const char *cmsg = tmp;
if ( prog >= 0 )
{
sprintf(tmp, "%s %i%%",msg,(int)(100*prog));
}
else
{
cmsg = msg;
}
cm->UpdateStatusBar(cmsg);
cm->PrintKeys(1);
curses_move(1,1);
touchwin(stdscr);
refresh();
}
int cmCursesMainForm::Configure() int cmCursesMainForm::Configure()
{ {
int xi,yi; int xi,yi;
getmaxyx(stdscr, yi, xi); getmaxyx(stdscr, yi, xi);
curses_clear();
curses_move(1,1); curses_move(1,1);
this->UpdateStatusBar("Configuring, please wait...");
this->PrintKeys(1);
touchwin(stdscr); touchwin(stdscr);
refresh(); refresh();
endwin();
std::cerr << "Configuring, please wait...\n\r";
this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this); this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
// always save the current gui values to disk // always save the current gui values to disk
@ -583,9 +647,6 @@ int cmCursesMainForm::Configure()
int retVal = this->m_CMakeInstance->Configure(); int retVal = this->m_CMakeInstance->Configure();
this->m_CMakeInstance->SetProgressCallback(0, 0); this->m_CMakeInstance->SetProgressCallback(0, 0);
initscr(); /* Initialization */
noecho(); /* Echo off */
cbreak(); /* nl- or cr not needed */
keypad(stdscr,TRUE); /* Use key symbols as keypad(stdscr,TRUE); /* Use key symbols as
KEY_DOWN*/ KEY_DOWN*/
@ -626,12 +687,11 @@ int cmCursesMainForm::Generate()
int xi,yi; int xi,yi;
getmaxyx(stdscr, yi, xi); getmaxyx(stdscr, yi, xi);
curses_clear();
curses_move(1,1); curses_move(1,1);
this->UpdateStatusBar("Generating, please wait...");
this->PrintKeys(1);
touchwin(stdscr); touchwin(stdscr);
refresh(); refresh();
endwin();
std::cerr << "Generating, please wait...\n\r";
this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this); this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
// Get rid of previous errors // Get rid of previous errors
@ -641,9 +701,6 @@ int cmCursesMainForm::Generate()
int retVal = this->m_CMakeInstance->Generate(); int retVal = this->m_CMakeInstance->Generate();
this->m_CMakeInstance->SetProgressCallback(0, 0); this->m_CMakeInstance->SetProgressCallback(0, 0);
initscr(); /* Initialization */
noecho(); /* Echo off */
cbreak(); /* nl- or cr not needed */
keypad(stdscr,TRUE); /* Use key symbols as keypad(stdscr,TRUE); /* Use key symbols as
KEY_DOWN*/ KEY_DOWN*/

View File

@ -22,6 +22,7 @@
#include "cmCursesStandardIncludes.h" #include "cmCursesStandardIncludes.h"
class cmCursesCacheEntryComposite; class cmCursesCacheEntryComposite;
class cmCursesWidget;
class cmake; class cmake;
/** \class cmCursesMainForm /** \class cmCursesMainForm
@ -65,17 +66,21 @@ public:
}; };
/** /**
* This method should normally called only by the form. * This method should normally be called only by the form. The only
* The only exception is during a resize. * exception is during a resize. The optional argument specifies the
* string to be displayed in the status bar.
*/ */
virtual void UpdateStatusBar(); virtual void UpdateStatusBar() { this->UpdateStatusBar(0); }
virtual void UpdateStatusBar(const char* message);
/** /**
* Display current commands and their keys on the toolbar. * Display current commands and their keys on the toolbar. This
* This method should normally called only by the form. * method should normally called only by the form. The only
* The only exception is during a resize. * exception is during a resize. If the optional argument process is
* specified and is either 1 (configure) or 2 (generate), then keys
* will be displayed accordingly.
*/ */
void PrintKeys(); void PrintKeys(int process = 0);
/** /**
* During a CMake run, an error handle should add errors * During a CMake run, an error handle should add errors
@ -101,6 +106,7 @@ public:
/** /**
* Progress callback * Progress callback
*/ */
static void UpdateProgressOld(const char *msg, float prog, void*);
static void UpdateProgress(const char *msg, float prog, void*); static void UpdateProgress(const char *msg, float prog, void*);
protected: protected: