Skip to content

Commit

Permalink
IMPROVE: Don't display ProgressBar if amount is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
spillerrec committed Mar 23, 2015
1 parent cb4ede6 commit c9eb44d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/ProgressBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ class ProgressBar{
* \param [in] size The width of the progress bar
*/
ProgressBar( std::string msg, int amount, int size=60 ) : amount(amount), size(size){
//Print slightly fancy header with centered text
msg += " (" + std::to_string( amount ) + ")";
int left = size - msg.size();

for( int i=0; i<size; i++ )
std::cout << "_";

std::cout << std::endl << "|";
for( int i=1; i<left/2; i++ )
std::cout << " ";
std::cout << msg;
for( int i=1; i<left-left/2; i++ )
std::cout << " ";
std::cout << "|" << std::endl;
if( amount > 0 ){
//Print slightly fancy header with centered text
msg += " (" + std::to_string( amount ) + ")";
int left = size - msg.size();

for( int i=0; i<size; i++ )
std::cout << "_";

std::cout << std::endl << "|";
for( int i=1; i<left/2; i++ )
std::cout << " ";
std::cout << msg;
for( int i=1; i<left-left/2; i++ )
std::cout << " ";
std::cout << "|" << std::endl;
}
}
/** Stops and closes the progress bar */
~ProgressBar(){ std::cout << std::endl; }
Expand Down

0 comments on commit c9eb44d

Please sign in to comment.