Documentation

ProgressBar
in package

Console progress bar class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

Table of Contents

Properties

$barChar  : string
Character used for the filled portion of the bar
$bg  : int|null
Background color of the filled portion
$current  : int
Current step
$emptyChar  : string
Character used for the unfilled portion of the bar
$fg  : int|null
Foreground color of the filled portion
$finished  : bool
Flag for if the progress bar has finished
$indent  : string
Indent prefix
$lastLine  : string|null
Last rendered line, so redraws are skipped when the visible output hasn't changed
$message  : string|null
Optional leading message
$progressChar  : string
Character used at the leading edge of the filled portion
$total  : int
Total number of steps
$width  : int
Width of the bar's fill portion

Methods

__construct()  : mixed
Instantiate the progress bar object
advance()  : ProgressBar
Advance the progress bar by the given number of steps
finish()  : ProgressBar
Finish the progress bar
getCurrent()  : int
Get the current progress
getTotal()  : int
Get the total number of steps
isFinished()  : bool
Determine if the progress bar has finished
setChars()  : ProgressBar
Set the bar characters
setColor()  : ProgressBar
Set the color of the filled portion of the bar
setIndent()  : ProgressBar
Set the indent prefix
setMessage()  : ProgressBar
Set the leading message
setProgress()  : ProgressBar
Set the current progress
setWidth()  : ProgressBar
Set the width of the bar's fill portion
buildLine()  : string
Build the progress bar line
render()  : void
Render the progress bar to the console

Properties

$barChar

Character used for the filled portion of the bar

protected string $barChar = '='

$bg

Background color of the filled portion

protected int|null $bg = null

$emptyChar

Character used for the unfilled portion of the bar

protected string $emptyChar = ' '

$fg

Foreground color of the filled portion

protected int|null $fg = null

$finished

Flag for if the progress bar has finished

protected bool $finished = false

$lastLine

Last rendered line, so redraws are skipped when the visible output hasn't changed

protected string|null $lastLine = null

$message

Optional leading message

protected string|null $message = null

$progressChar

Character used at the leading edge of the filled portion

protected string $progressChar = '>'

$width

Width of the bar's fill portion

protected int $width = 28

Methods

__construct()

Instantiate the progress bar object

public __construct(int $total[, string|null $message = null ][, int $width = 28 ]) : mixed
Parameters
$total : int
$message : string|null = null
$width : int = 28
Tags
throws
Exception

advance()

Advance the progress bar by the given number of steps

public advance([int $step = 1 ]) : ProgressBar
Parameters
$step : int = 1
Return values
ProgressBar

getCurrent()

Get the current progress

public getCurrent() : int
Return values
int

getTotal()

Get the total number of steps

public getTotal() : int
Return values
int

isFinished()

Determine if the progress bar has finished

public isFinished() : bool
Return values
bool

setChars()

Set the bar characters

public setChars([string $barChar = '=' ][, string $progressChar = '>' ][, string $emptyChar = ' ' ]) : ProgressBar
Parameters
$barChar : string = '='
$progressChar : string = '>'
$emptyChar : string = ' '
Return values
ProgressBar

setColor()

Set the color of the filled portion of the bar

public setColor(int|null $fg[, int|null $bg = null ]) : ProgressBar
Parameters
$fg : int|null
$bg : int|null = null
Return values
ProgressBar

buildLine()

Build the progress bar line

protected buildLine() : string
Return values
string

render()

Render the progress bar to the console

protected render() : void

        
On this page

Search results