Page MenuHomePhabricator
Diviner libphutil Tech Docs PhutilConsoleProgressBar

final class PhutilConsoleProgressBar
libphutil Technical Documentation (Console)

Show a progress bar on the console. Usage:

// Create a progress bar, and configure the total amount of work that
// needs to be done.
$bar = id(new PhutilConsoleProgressBar())
  ->setTotal(count($stuff));

// As you complete the work, update the progress bar.
foreach ($stuff as $thing) {
  do_stuff($thing);
  $bar->update(1);
}

// When complete, mark the work done to clear the bar.
$bar->done();

The progress bar attempts to account for various special cases, notably:

  • If stderr is not a TTY, the bar will not be drawn (for example, if it is being piped to a log file).
  • If the Phutil log output is enabled (usually because --trace was specified), the bar will not be drawn.
  • The bar will be resized to the width of the console if possible.

Methods

public function setConsole($console)

This method is not documented.
Parameters
PhutilConsole$console
Return
wild

private function getConsole()

This method is not documented.
Return
wild

public function setTotal($work)

This method is not documented.
Parameters
$work
Return
wild

public function setQuiet($quiet)

This method is not documented.
Parameters
$quiet
Return
wild

public function update($work)

This method is not documented.
Parameters
$work
Return
wild

private function redraw()

This method is not documented.
Return
wild

public function draw()

Explicitly redraw the bar.

Normally, the progress bar is automatically redrawn periodically, but you may want to force it to draw.

For example, we force a draw after pre-filling the bar when resuming large file uploads in arc upload. Otherwise, the bar may sit at 0% until the first chunk completes.

Return
wild

public function done($clean_exit)

This method is not documented.
Parameters
$clean_exit
Return
wild

private function eraseLine()

This method is not documented.
Return
wild

private function getWidth()

This method is not documented.
Return
wild

public function __destruct()

This method is not documented.
Return
wild