ConsoleTools: ezcConsoleProgressbar
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcConsoleProgressbar
|
Creating and maintaining progress-bars to be printed to the console. [
source]
1. $out = new ezcConsoleOutput();
2.
3. // Create progress bar itself
4. $progress = new ezcConsoleProgressbar( $out, 100, array( 'step' => 5 ) );
5.
6. $progress->options->emptyChar = '-';
7. $progress->options->progressChar = '#';
8. $progress->options->formatString = "Uploading file </tmp/foobar.tar.bz2>: %act%/%max% kb [%bar%]";
9.
10. // Perform actions
11. $i = 0;
12. while ( $i++ < 20 )
13. {
14. // Do whatever you want to indicate progress for
15. usleep( mt_rand( 20000, 2000000 ) );
16. // Advance the progressbar by one step ( uploading 5k per run )
17. $progress->advance();
18. }
19.
20. // Finish progress bar and jump to next line.
21. $progress->finish();
22.
23. $out->outputText( "Successfully uploaded </tmp/foobar.tar.bz2>.\n", 'success' );
Properties
Member Variables
|
protected int |
$currentStep
= 0
The current step the progress bar should show. |
|
protected array(string |
$measures
= array( 'barSpace' => 0, 'fractionSpace' => 0, 'actSpace' => 0, 'maxSpace' => 0, 'fixedCharSpace' => 0, )
Stores the bar utilization. |
|
protected int |
$numSteps
= 0
The maximum number of steps to go. |
|
protected ezcConsoleOutput |
$output
The ezcConsoleOutput object to use. |
|
protected array(string=>mixed) |
$properties
Container to hold the properties |
|
protected bool |
$started
= false
Indicates if the starting point for the bar has been stored. |
|
protected array(string |
$valueMap
= array( 'bar' => '', 'fraction' => '', 'act' => '', 'max' => '', )
Storage for actual values to be replaced in the format string. |
Method Summary
|
public ezcConsoleProgressbar |
__construct(
$outHandler, $max, [$options = array()] )
Creates a new progress bar. |
|
public void |
advance(
[$redraw = true], [$step = 1], $steps )
Advance the progress bar. |
|
protected void |
calculateMeasures(
)
Calculate several measures necessary to generate a bar. |
|
public void |
finish(
)
Finish the progress bar. |
|
protected void |
generateValues(
)
Generate all values to be replaced in the format string. |
|
public ezcConsoleProgressbarOptions |
getOptions(
)
Returns the current options. |
|
protected void |
insertValues(
)
Insert values into bar format string. |
|
public void |
output(
)
Draw the progress bar. |
|
public void |
setOptions(
$options )
Set new options. |
|
public void |
start(
)
Start the progress bar Starts the progress bar and sticks it to the current line. |
|
protected void |
stripEscapeSequences(
$str )
Strip all escape sequences from a string to measure it's size correctly. |
Methods
__construct
ezcConsoleProgressbar __construct(
ezcConsoleOutput
$outHandler, int
$max, [
$options = array()] )
Creates a new progress bar.
Parameters
| Name |
Type |
Description |
$outHandler |
ezcConsoleOutput |
Handler to utilize for output |
$max |
int |
Maximum value, where progressbar reaches 100%. |
$options |
array(string=>string) |
Options |
See also:
ezcConsoleProgressbar::$options.
advance
void advance(
[bool
$redraw = true], [
$step = 1], float
$steps )
Advance the progress bar.
Parameters
| Name |
Type |
Description |
$redraw |
bool |
Whether to redraw the bar immediately. |
$steps |
float |
How far the progress bar should advance on this call. |
$step |
|
|
calculateMeasures
void calculateMeasures(
)
Calculate several measures necessary to generate a bar.
finish
void finish(
)
Finish the progress bar.
Finishes the bar (jump to 100% if not happened yet,...) and jumps to the next line to allow new output. Also resets the values of the output handler used, if changed.
generateValues
void generateValues(
)
Generate all values to be replaced in the format string.
getOptions
Returns the current options.
Returns the options currently set for this progressbar.
insertValues
void insertValues(
)
Insert values into bar format string.
output
void output(
)
Draw the progress bar.
Prints the progress-bar to the screen. If start() has not been called yet, the current line is used for ezcConsolProgressbar::start().
setOptions
void setOptions(
ezcConsoleProgresbarOptions
$options )
Set new options.
This method allows you to change the options of progressbar.
Parameters
| Name |
Type |
Description |
$options |
ezcConsoleProgresbarOptions |
The options to set. |
Throws
| Class | Description |
ezcBaseSettingNotFoundException |
If you tried to set a non-existent option value. |
ezcBaseSettingValueException |
If the value is not valid for the desired option. |
ezcBaseValueException |
If you submit neither an array nor an instance of ezcConsoleProgresbarOptions. |
start
void start(
)
Start the progress bar Starts the progress bar and sticks it to the current line.
stripEscapeSequences
void stripEscapeSequences(
mixed
$str )
Strip all escape sequences from a string to measure it's size correctly.
Parameters
| Name |
Type |
Description |
$str |
mixed |
|
Last updated: Thu, 01 Nov 2007