Skip to content

Commit

Permalink
Don't redraw the progress bar unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafik committed Jul 19, 2015
1 parent 13df22c commit 0bd4cb1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/TerminalObject/Dynamic/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Progress extends DynamicTerminalObject
*/
protected $current = 0;

/**
* The current percentage displayed
*
* @var string $currentPercentage
*/
protected $currentPercentage = '';

/**
* The string length of the bar when at 100%
*
Expand All @@ -32,6 +39,13 @@ class Progress extends DynamicTerminalObject
*/
protected $first_line = true;

/**
* Current status bar label
*
* @var string $label
*/
protected $label;

/**
* If they pass in a total, set the total
*
Expand Down Expand Up @@ -76,11 +90,15 @@ public function current($current, $label = null)
throw new \Exception('The current is greater than the total.');
}

$progress_bar = $this->getProgressBar($current, $label);

$this->output->write($this->parser->apply($progress_bar));
$currentPercentage = $this->percentageFormatted($current / $this->total);
if ($currentPercentage != $this->currentPercentage || $label != $this->label) {
$progress_bar = $this->getProgressBar($current, $label);
$this->output->write($this->parser->apply($progress_bar));
}

$this->current = $current;
$this->currentPercentage = $currentPercentage;
$this->label = $label;
}

/**
Expand Down

0 comments on commit 0bd4cb1

Please sign in to comment.