Console_ProgressBar
[ class tree: Console_ProgressBar ] [ index: Console_ProgressBar ] [ all elements ]

Class: Console_ProgressBar

Source Location: /Console_ProgressBar-0.5.2beta/ProgressBar.php

Class Overview


Class to display a progressbar in the console


Author(s):

Version:

  • 0.5.2

Methods


Inherited Variables

Inherited Methods


Class Details

[line 37]
Class to display a progressbar in the console
  • Author: Stefan Walk <et@php.net>
  • Version: 0.5.2
  • License: MIT


[ Top ]


Method Detail

Console_ProgressBar (Constructor)   [line 93]

Console_ProgressBar Console_ProgressBar( string $formatstring, string $bar, string $prefill, int $width, float $target_num, [array $options = array()])

Constructor, sets format and size

See the reset() method for documentation.


Parameters:

string   $formatstring   —  The format string
string   $bar   —  The string filling the progress bar
string   $prefill   —  The string filling empty space in the bar
int   $width   —  The width of the display
float   $target_num   —  The target number for the bar
array   $options   —  Options for the progress bar

[ Top ]

display   [line 302]

bool display( int $current)

Prints the bar. Usually, you don't need this method, just use update() which handles erasing the previously printed bar also. If you use a custom function (for whatever reason) to erase the bar, use this method.

Parameters:

int   $current   —  current position of the progress counter

[ Top ]

erase   [line 335]

bool erase( [bool $clear = false])

Erases a previously printed bar.

Parameters:

bool   $clear   —  if the bar should be cleared in addition to resetting the cursor position

[ Top ]

reset   [line 183]

bool reset( string $formatstring, string $bar, string $prefill, int $width, float $target_num, [array $options = array()])

Re-sets format and size.

 The reset method expects 5 to 6 arguments:
 - The first argument is the format string used to display the progress
   bar. It may (and should) contain placeholders that the class will
   replace with information like the progress bar itself, the progress in
   percent, and so on. Current placeholders are:
     %bar%         The progress bar
     %current%     The current value
     %max%         The maximum malue (the "target" value)
     %fraction%    The same as %current%/%max%
     %percent%     The status in percent
     %elapsed%     The elapsed time
     %estimate%    An estimate of how long the progress will take
   More placeholders will follow. A format string like:
   "* stuff.tar %fraction% KB [%bar%] %percent%"
   will lead to a bar looking like this:
   "* stuff.tar 391/900 KB [=====>---------]  43.44%"
 - The second argument is the string that is going to fill the progress
   bar. In the above example, the string "=>" was used. If the string you
   pass is too short (like "=>" in this example), the leftmost character
   is used to pad it to the needed size. If the string you pass is too long,
   excessive characters are stripped from the left.
 - The third argument is the string that fills the "empty" space in the
   progress bar. In the above example, that would be "-". If the string
   you pass is too short (like "-" in this example), the rightmost
   character is used to pad it to the needed size. If the string you pass
   is too short, excessive characters are stripped from the right.
 - The fourth argument specifies the width of the display. If the options
   are left untouched, it will tell how many characters the display should
   use in total. If the "absolute_width" option is set to false, it tells
   how many characters the actual bar (that replaces the %bar%
   placeholder) should use.
 - The fifth argument is the target number of the progress bar. For
   example, if you wanted to display a progress bar for a download of a
   file that is 115 KB big, you would pass 115 here.
 - The sixth argument optional. If passed, it should contain an array of
   options. For example, passing array('absolute_width' => false) would
   set the absolute_width option to false. Current options are:

     option             | def.  |  meaning
     --------------------------------------------------------------------
     percent_precision  | 2     |  Number of decimal places to show when
                        |       |  displaying the percentage.
     fraction_precision | 0     |  Number of decimal places to show when
                        |       |  displaying the current or target
                        |       |  number.
     percent_pad        | ' '   |  Character to use when padding the
                        |       |  percentage to a fixed size. Senseful
                        |       |  values are ' ' and '0', but any are
                        |       |  possible.
     fraction_pad       | ' '   |  Character to use when padding max and
                        |       |  current number to a fixed size.
                        |       |  Senseful values are ' ' and '0', but
                        |       |  any are possible.
     width_absolute     | true  |  If the width passed as an argument
                        |       |  should mean the total size (true) or
                        |       |  the width of the bar alone.
     ansi_terminal      | false |  If this option is true, a better
                        |       |  (faster) method for erasing the bar is
                        |       |  used. CAUTION - this is known to cause
                        |       |  problems with some terminal emulators,
                        |       |  for example Eterm.
     ansi_clear         | false |  If the bar should be cleared everytime
     num_datapoints     | 5     |  How many datapoints to use to create
                        |       |  the estimated remaining time
     min_draw_interval  | 0.0   |  If the last call to update() was less
                        |       |  than this amount of seconds ago,
                        |       |  don't update.


Parameters:

string   $formatstring   —  The format string
string   $bar   —  The string filling the progress bar
string   $prefill   —  The string filling empty space in the bar
int   $width   —  The width of the display
float   $target_num   —  The target number for the bar
array   $options   —  Options for the progress bar

[ Top ]

update   [line 270]

bool update( int $current)

Updates the bar with new progress information

Parameters:

int   $current   —  current position of the progress counter

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:11:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.