Path

ez components / documentation / api reference / 1.0.1 / consoletools


eZ Components 1.0.1

ConsoleTools: ezcConsoleProgressbar

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcConsoleProgressbar

Creating and maintaining progressbars to be printed to the console. [source]
 1.  $out new ezcConsoleOutput();
 2.  
 3.  // Create progress bar itself
 4.   $progress new ezcConsoleProgressbar$out100array'step' => ) );
 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.           usleepmt_rand200002000000 ) );
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' );

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,
)

One tima calculated measures.
protected int $numSteps = 0
The maximum number of steps to go.
protected ezcConsoleProgressbarOptions $options
Options
protected ezcConsoleOutput $output
The ezcConsoleOutput object to use.
protected array(string=>int) $settings
Settings for the progress bar.
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] )
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.
protected void insertValues( )
Insert values into bar format string.
public void output( )
Draw the progress bar.
public void setOptions( $options )
Set options.
public void start( )
Start the progress bar Starts the progess 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.
public mixed __get( $key )
Property read access.
public bool __isset( $key )
Property isset access.
public void __set( $key, $val )
Property write access.

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::$optionsezcConsoleProgressbar::$settings.


advance

void advance( [mixed $redraw = true] )
Advance the progress bar.
Advances the progress bar by one step. Redraws the bar by default, using the ezcConsoleProgressbar::output() method.

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.

insertValues

void insertValues( )
Insert values into bar format string.

output

void output( )
Draw the progress bar.
Prints the progressbar to the screen. If start() has not been called yet, the current line is used for ezcConsolProgressbar::start().

setOptions

void setOptions( $options )
Set options.
Set the options of the progressbar.

Parameters

Name Type Description
$options array(string=>string) The options to set.

See also:

ezcConsoleProgressbarOptions.


start

void start( )
Start the progress bar Starts the progess bar and sticks it to the current line.
No output will be done yet. Call ezcConsoleProgressbar::output() to print the bar.

stripEscapeSequences

void stripEscapeSequences( mixed $str )
Strip all escape sequences from a string to measure it's size correctly.

Parameters

Name Type Description
$str mixed  

__get

mixed __get( string $key )
Property read access.

Parameters

Name Type Description
$key string Name of the property.

Throws

ClassDescription
ezcBasePropertyNotFoundException If the the desired property is not found.

__isset

bool __isset( string $key )
Property isset access.

Parameters

Name Type Description
$key string Name of the property.

__set

void __set( string $key, mixed $val )
Property write access.

Parameters

Name Type Description
$key string Name of the property.
$val mixed The value for the property.

Throws

ClassDescription
ezcBasePropertyNotFoundException If a desired property could not be found.
ezcBaseValueException If a desired property value is out of range.

Last updated: Fri, 02 Nov 2007