forked from consolidation/robo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple \Symfony\Component\Console\Helper\ProgressBar from tasks tha…
…t use progress indicators.
- Loading branch information
1 parent
f213930
commit 1ae7711
Showing
8 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
namespace Robo\Common; | ||
|
||
trait ProgressIndicatorAwareTrait | ||
{ | ||
use Timer; | ||
|
||
protected $progressIndicator; | ||
protected $progressIndicatorRunning = false; | ||
|
||
public function setProgressIndicator($progressIndicator) | ||
{ | ||
$this->progressIndicator = $progressIndicator; | ||
} | ||
|
||
public function hideProgressIndicator() | ||
{ | ||
if ($this->progressIndicatorRunning) { | ||
$this->progressIndicator->clear(); | ||
// Hack: progress indicator does not reset cursor to beginning of line on 'clear' | ||
\Robo\Config::output()->write("\x0D"); | ||
} | ||
} | ||
|
||
public function showProgressIndicator() | ||
{ | ||
if ($this->progressIndicatorRunning) { | ||
$this->progressIndicator->display(); | ||
} | ||
} | ||
|
||
public function startProgressIndicator($totalSteps = 0) | ||
{ | ||
$this->startTimer(); | ||
if (isset($this->progressIndicator)) { | ||
$this->progressIndicator->start($totalSteps); | ||
$this->progressIndicator->display(); | ||
$this->progressIndicatorRunning = true; | ||
} | ||
} | ||
|
||
public function stopProgressIndicator() | ||
{ | ||
$this->stopTimer(); | ||
if ($this->progressIndicatorRunning) { | ||
$this->progressIndicatorRunning = false; | ||
$this->progressIndicator->finish(); | ||
// Hack: progress indicator does not always finish cleanly | ||
\Robo\Config::output()->writeln(''); | ||
} | ||
} | ||
|
||
public function advanceProgressIndicator($steps = 1) | ||
{ | ||
if ($this->progressIndicatorRunning) { | ||
$this->progressIndicator->advance($steps); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace Robo\Contract; | ||
|
||
/** | ||
* Any Robo task that uses the Timer trait and | ||
* implements ProgressIndicatorAwareInterface will | ||
* display a progress bar while the timer is running. | ||
* Call advanceProgressIndicator to advance the indicator. | ||
* | ||
* Interface ProgressIndicatorAwareInterface | ||
* @package Robo\Contract | ||
*/ | ||
interface ProgressIndicatorAwareInterface | ||
{ | ||
public function setProgressIndicator($progressIndicator); | ||
public function startProgressIndicator($totalSteps = 0); | ||
public function stopProgressIndicator(); | ||
public function hideProgressIndicator(); | ||
public function showProgressIndicator(); | ||
public function advanceProgressIndicator($steps = 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
$message = $argv[1]; | ||
$iterations = $argv[2]; | ||
for ($i=0; $i < $iterations; ++$i) { | ||
print "$message\n"; | ||
sleep(1); | ||
} |