Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcConsoleProgressbar

ConsoleTools::ezcConsoleProgressbar

Class ezcConsoleProgressbar

Creating and maintaining progress-bars to be printed to the console.

  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' );

Source for this file: /ConsoleTools/src/progressbar.php

Version:   //autogen//

Properties

int read/write $max
The maximum progress value to reach.
ezcConsoleProgressbarOptions read/write $options
Contains the options for this class.

Member Variables

protected int $currentStep = 0
The current step the progress bar should show.
protected array(string=>int) $measures = array(
'barSpace' => 0,
'fractionSpace' => 0,
'actSpace' => 0,
'maxSpace' => 0,
'fixedCharSpace' => 0,
)

Stores the bar utilization.

This array saves how much space a specific part of the bar utilizes to not recalculate those on every step.

protected int $numSteps = 0
The maximum number of steps to go.

Calculated once from the settings.

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.

Per default this is false to indicate that no start position has been stored, yet.

protected array(string=>string) $valueMap = array(
'bar' => '',
'fraction' => '',
'act' => '',
'max' => '',
)

Storage for actual values to be replaced in the format string.

Actual values are stored here and will be inserted into the bar before printing it.

Method Summary

public ezcConsoleProgressbar __construct( $outHandler , $max , [ $options = array()] )
Creates a new progress bar.
public void advance( [ $redraw = true] , [ $step = 1] )
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

advance

void advance( [bool $redraw = true] , [int $step = 1] )

Advance the progress bar.

Advances the progress bar by $step steps. Redraws the bar by default, using the ezcConsoleProgressbar::output() method.

Parameters:
Name Type Description
$redraw bool Whether to redraw the bar immediately.
$step int How many steps to advance.

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.
Exceptions:
Type 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.

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
Documentation generated by phpDocumentor 1.4.3