ProgressBar
in package
The ProgressBar provides helpers to display progress output.
Tags
Table of Contents
Constants
- FORMAT_DEBUG = 'debug'
- FORMAT_NORMAL = 'normal'
- FORMAT_VERBOSE = 'verbose'
- FORMAT_VERY_VERBOSE = 'very_verbose'
- FORMAT_DEBUG_NOMAX = 'debug_nomax'
- FORMAT_NORMAL_NOMAX = 'normal_nomax'
- FORMAT_VERBOSE_NOMAX = 'verbose_nomax'
- FORMAT_VERY_VERBOSE_NOMAX = 'very_verbose_nomax'
Properties
- $barChar : string
- $barWidth : int
- $cursor : Cursor
- $emptyBarChar : string
- $format : string|null
- $formats : array<string|int, mixed>
- $formatters : array<string|int, mixed>
- $internalFormat : string|null
- $lastWriteTime : float
- $max : int|null
- $maxSecondsBetweenRedraws : float
- $messages : array<string|int, mixed>
- $minSecondsBetweenRedraws : float
- $output : OutputInterface
- $overwrite : bool
- $percent : float
- $placeholders : array<string|int, mixed>
- $previousMessage : string|null
- $progressChar : string
- $redrawFreq : int|null
- $startingStep : int
- $startTime : int
- $step : int
- $stepWidth : int
- $terminal : Terminal
- $writeCount : int
Methods
- __construct() : mixed
- advance() : void
- Advances the progress output X steps.
- clear() : void
- Removes the progress bar from the current line.
- display() : void
- Outputs the current progress string.
- finish() : void
- Finishes the progress output.
- getBarCharacter() : string
- getBarOffset() : float
- getBarWidth() : int
- getEmptyBarCharacter() : string
- getEstimated() : float
- getFormatDefinition() : string|null
- Gets the format for a given name.
- getMaxSteps() : int
- getMessage() : string|null
- getPlaceholderFormatter() : callable|null
- Gets the placeholder formatter for a given name.
- getPlaceholderFormatterDefinition() : callable|null
- Gets the placeholder formatter for a given name.
- getProgress() : int
- getProgressCharacter() : string
- getProgressPercent() : float
- getRemaining() : float
- getStartTime() : int
- iterate() : iterable<TKey, TValue>
- Returns an iterator that will automatically update the progress bar when iterated.
- maxSecondsBetweenRedraws() : void
- minSecondsBetweenRedraws() : void
- setBarCharacter() : void
- setBarWidth() : void
- setEmptyBarCharacter() : void
- setFormat() : void
- setFormatDefinition() : void
- Sets a format for a given name.
- setMaxSteps() : void
- setMessage() : void
- Associates a text with a named placeholder.
- setOverwrite() : void
- Sets whether to overwrite the progressbar, false for new line.
- setPlaceholderFormatter() : void
- Sets a placeholder formatter for a given name, for this instance only.
- setPlaceholderFormatterDefinition() : void
- Sets a placeholder formatter for a given name, globally for all instances of ProgressBar.
- setProgress() : void
- setProgressCharacter() : void
- setRedrawFrequency() : void
- Sets the redraw frequency.
- start() : void
- Starts the progress output.
- buildLine() : string
- determineBestFormat() : string
- getStepWidth() : int
- initFormats() : array<string|int, mixed>
- initPlaceholderFormatters() : array<string|int, mixed>
- overwrite() : void
- Overwrites a previous message to the output.
- setRealFormat() : void
Constants
FORMAT_DEBUG
public
mixed
FORMAT_DEBUG
= 'debug'
FORMAT_NORMAL
public
mixed
FORMAT_NORMAL
= 'normal'
FORMAT_VERBOSE
public
mixed
FORMAT_VERBOSE
= 'verbose'
FORMAT_VERY_VERBOSE
public
mixed
FORMAT_VERY_VERBOSE
= 'very_verbose'
FORMAT_DEBUG_NOMAX
private
mixed
FORMAT_DEBUG_NOMAX
= 'debug_nomax'
FORMAT_NORMAL_NOMAX
private
mixed
FORMAT_NORMAL_NOMAX
= 'normal_nomax'
FORMAT_VERBOSE_NOMAX
private
mixed
FORMAT_VERBOSE_NOMAX
= 'verbose_nomax'
FORMAT_VERY_VERBOSE_NOMAX
private
mixed
FORMAT_VERY_VERBOSE_NOMAX
= 'very_verbose_nomax'
Properties
$barChar
private
string
$barChar
$barWidth
private
int
$barWidth
= 28
$cursor
private
Cursor
$cursor
$emptyBarChar
private
string
$emptyBarChar
= '-'
$format
private
string|null
$format
= null
$formats
private
static array<string|int, mixed>
$formats
$formatters
private
static array<string|int, mixed>
$formatters
$internalFormat
private
string|null
$internalFormat
= null
$lastWriteTime
private
float
$lastWriteTime
= 0
$max
private
int|null
$max
= null
$maxSecondsBetweenRedraws
private
float
$maxSecondsBetweenRedraws
= 1
$messages
private
array<string|int, mixed>
$messages
= []
$minSecondsBetweenRedraws
private
float
$minSecondsBetweenRedraws
= 0
$output
private
OutputInterface
$output
$overwrite
private
bool
$overwrite
= true
$percent
private
float
$percent
= 0.0
$placeholders
private
array<string|int, mixed>
$placeholders
= []
$previousMessage
private
string|null
$previousMessage
= null
$progressChar
private
string
$progressChar
= '>'
$redrawFreq
private
int|null
$redrawFreq
= 1
$startingStep
private
int
$startingStep
= 0
$startTime
private
int
$startTime
$step
private
int
$step
= 0
$stepWidth
private
int
$stepWidth
$terminal
private
Terminal
$terminal
$writeCount
private
int
$writeCount
= 0
Methods
__construct()
public
__construct(OutputInterface $output[, int $max = 0 ][, float $minSecondsBetweenRedraws = 1 / 25 ]) : mixed
Parameters
- $output : OutputInterface
- $max : int = 0
-
Maximum steps (0 if unknown)
- $minSecondsBetweenRedraws : float = 1 / 25
advance()
Advances the progress output X steps.
public
advance([int $step = 1 ]) : void
Parameters
- $step : int = 1
-
Number of steps to advance
clear()
Removes the progress bar from the current line.
public
clear() : void
This is useful if you wish to write some output while a progress bar is running. Call display() to show the progress bar again.
display()
Outputs the current progress string.
public
display() : void
finish()
Finishes the progress output.
public
finish() : void
getBarCharacter()
public
getBarCharacter() : string
Return values
stringgetBarOffset()
public
getBarOffset() : float
Return values
floatgetBarWidth()
public
getBarWidth() : int
Return values
intgetEmptyBarCharacter()
public
getEmptyBarCharacter() : string
Return values
stringgetEstimated()
public
getEstimated() : float
Return values
floatgetFormatDefinition()
Gets the format for a given name.
public
static getFormatDefinition(string $name) : string|null
Parameters
- $name : string
-
The format name
Return values
string|nullgetMaxSteps()
public
getMaxSteps() : int
Return values
intgetMessage()
public
getMessage([string $name = 'message' ]) : string|null
Parameters
- $name : string = 'message'
Return values
string|nullgetPlaceholderFormatter()
Gets the placeholder formatter for a given name.
public
getPlaceholderFormatter(string $name) : callable|null
Parameters
- $name : string
-
The placeholder name (including the delimiter char like %)
Return values
callable|nullgetPlaceholderFormatterDefinition()
Gets the placeholder formatter for a given name.
public
static getPlaceholderFormatterDefinition(string $name) : callable|null
Parameters
- $name : string
-
The placeholder name (including the delimiter char like %)
Return values
callable|nullgetProgress()
public
getProgress() : int
Return values
intgetProgressCharacter()
public
getProgressCharacter() : string
Return values
stringgetProgressPercent()
public
getProgressPercent() : float
Return values
floatgetRemaining()
public
getRemaining() : float
Return values
floatgetStartTime()
public
getStartTime() : int
Return values
intiterate()
Returns an iterator that will automatically update the progress bar when iterated.
public
iterate(iterable<TKey, TValue> $iterable[, int|null $max = null ]) : iterable<TKey, TValue>
Parameters
- $iterable : iterable<TKey, TValue>
- $max : int|null = null
-
Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable
Tags
Return values
iterable<TKey, TValue>maxSecondsBetweenRedraws()
public
maxSecondsBetweenRedraws(float $seconds) : void
Parameters
- $seconds : float
minSecondsBetweenRedraws()
public
minSecondsBetweenRedraws(float $seconds) : void
Parameters
- $seconds : float
setBarCharacter()
public
setBarCharacter(string $char) : void
Parameters
- $char : string
setBarWidth()
public
setBarWidth(int $size) : void
Parameters
- $size : int
setEmptyBarCharacter()
public
setEmptyBarCharacter(string $char) : void
Parameters
- $char : string
setFormat()
public
setFormat(string $format) : void
Parameters
- $format : string
setFormatDefinition()
Sets a format for a given name.
public
static setFormatDefinition(string $name, string $format) : void
This method also allow you to override an existing format.
Parameters
- $name : string
-
The format name
- $format : string
-
A format string
setMaxSteps()
public
setMaxSteps(int $max) : void
Parameters
- $max : int
setMessage()
Associates a text with a named placeholder.
public
setMessage(string $message[, string $name = 'message' ]) : void
The text is displayed when the progress bar is rendered but only when the corresponding placeholder is part of the custom format line (by wrapping the name with %).
Parameters
- $message : string
-
The text to associate with the placeholder
- $name : string = 'message'
-
The name of the placeholder
setOverwrite()
Sets whether to overwrite the progressbar, false for new line.
public
setOverwrite(bool $overwrite) : void
Parameters
- $overwrite : bool
setPlaceholderFormatter()
Sets a placeholder formatter for a given name, for this instance only.
public
setPlaceholderFormatter(string $name, callable(ProgressBar): string $callable) : void
Parameters
- $name : string
- $callable : callable(ProgressBar): string
-
A PHP callable
setPlaceholderFormatterDefinition()
Sets a placeholder formatter for a given name, globally for all instances of ProgressBar.
public
static setPlaceholderFormatterDefinition(string $name, callable(ProgressBar): string $callable) : void
This method also allow you to override an existing placeholder.
Parameters
- $name : string
-
The placeholder name (including the delimiter char like %)
- $callable : callable(ProgressBar): string
-
A PHP callable
setProgress()
public
setProgress(int $step) : void
Parameters
- $step : int
setProgressCharacter()
public
setProgressCharacter(string $char) : void
Parameters
- $char : string
setRedrawFrequency()
Sets the redraw frequency.
public
setRedrawFrequency(int|null $freq) : void
Parameters
- $freq : int|null
-
The frequency in steps
start()
Starts the progress output.
public
start([int|null $max = null ][, int $startAt = 0 ]) : void
Parameters
- $max : int|null = null
-
Number of steps to complete the bar (0 if indeterminate), null to leave unchanged
- $startAt : int = 0
-
The starting point of the bar (useful e.g. when resuming a previously started bar)
buildLine()
private
buildLine() : string
Return values
stringdetermineBestFormat()
private
determineBestFormat() : string
Return values
stringgetStepWidth()
private
getStepWidth() : int
Return values
intinitFormats()
private
static initFormats() : array<string|int, mixed>
Return values
array<string|int, mixed>initPlaceholderFormatters()
private
static initPlaceholderFormatters() : array<string|int, mixed>
Return values
array<string|int, mixed>overwrite()
Overwrites a previous message to the output.
private
overwrite(string $message) : void
Parameters
- $message : string
setRealFormat()
private
setRealFormat(string $format) : void
Parameters
- $format : string