Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,85 +1,78 @@
<?php
/*
/**
* CakePHP shell task for doing a simple progress bar
* Copyright (c) 2010 Matt Curry
* www.PseudoCoder.com
* http://github.com/mcurry/progress_bar
*
* @author Matt Curry <[email protected]>
* @license MIT
*
*/

App::uses('AppShell', 'Console/Command');

/**
* ProgressBarTask class
*
* @uses Shell
* @package progress_bar
* @subpackage progress_bar.vendors.shells.tasks
* @uses AppShell
* @package ProgressBar
* @subpackage ProgressBar.Console.Command.Task
*/
class ProgressBarTask extends Shell {
class ProgressBarTask extends AppShell {

/**
* Console Width
*
* @var int
* @access public
*/
public $terminalWidth = null;

/**
* message displayed during updates
*
* @var string ''
* @access public
*/
public $message = '';

/**
* Maximum value on the bar
*
* @var int
* @access public
*/
public $total = 100;

/**
* Size
*
* @var int
* @access public
*/
public $size = 25;

/**
* Amount Completed
*
* @var int
* @access public
*/
public $done = 0;

/**
* Start Time
*
* @var mixed
* @access public
*/
public $startTime = null;

/**
* String length for the previous line. Used to overwrite hanging chars/
*
* @var int
* @access public
*/
public $strLenPrevLine = null;

/**
* Execute the task - nothing to do by default
*
* @return void
* @access public
*/
public function execute() {
}
Expand All @@ -91,7 +84,6 @@ public function execute() {
* if you don't know the exact number of steps it's going to take
*
* @return void
* @access public
*/
public function finish() {
if ($this->done < $this->total) {
Expand All @@ -104,7 +96,6 @@ public function finish() {
*
* @param string $message ''
* @return void
* @access public
*/
public function message($message = '') {
$this->message = $message;
Expand All @@ -113,8 +104,8 @@ public function message($message = '') {
/**
* Increment the progress
*
* @param integer $inc increment value
* @return void
* @access public
*/
public function next($inc = 1) {
$this->done += $inc;
Expand All @@ -129,26 +120,19 @@ public function next($inc = 1) {
*
* @param mixed $message A string or a an array of strings to output
* @param integer $newlines Number of newlines to append
* @param integer $level The message's output level
* @return integer Returns the number of bytes returned from writing to stdout.
* @access public
*/
public function out($message = null, $newLines = 0) {
return parent::out($message, $newLines);
public function out($message = null, $newlines = 0, $level = Shell::NORMAL) {
return parent::out($message, $newlines, $level);
}

/**
* Set the values and output
*
* @return void
* @access public
*/
/**
* set method
*
* @param string $done Amount completed
* @param string $doneSize bar size
* @return void
* @access public
*/
public function set($done = null, $doneSize = null) {
if ($done) {
Expand Down Expand Up @@ -198,8 +182,8 @@ public function set($done = null, $doneSize = null) {
* Start a progress bar
*
* @param string $total Total value of the progress bar
* @param boolean $clear append one line
* @return void
* @access public
*/
public function start($total, $clear = true) {
$this->total = $total;
Expand All @@ -215,7 +199,6 @@ public function start($total, $clear = true) {
* Calculate remaining time in a nice format
*
* @return void
* @access public
*/
protected function _niceRemaining() {
$now = time();
Expand Down Expand Up @@ -243,7 +226,6 @@ protected function _niceRemaining() {
* @TODO can you get windows to tell you the size of the terminal?
* @param mixed $width null
* @return void
* @access protected
*/
protected function _setTerminalWidth($width = null) {
if ($width === null) {
Expand All @@ -257,5 +239,5 @@ protected function _setTerminalWidth($width = null) {
$this->size = min(max(4, $width / 10), $this->size);
$this->terminalWidth = $width;
}

}
?>
Loading