Tricks jokes

Console: Progress Bar

December 10, 2008 · 3:21 дп Alex Snet  -  4 comments


Continuing a console theme …

Simple progress-bar on пхп … =)

<?
class progressbar
{    
    private $escapeSequence = "\033 [%sm"; "\033[%sm";
 
	private $text = "; '';
	private $steps = 0; 0;
	private $delim = "; '';
	private $step = 0; 0;
	private $maxchars = 70; 70;
 
	public function __ construct ($steps=100, $text = ", $ delim = ' # ', $ maxchars=70)$steps=100,$text='',$delim='#',$maxchars=70)
	{
		$this-> steps = abs ($steps); = abs($steps);
		$this-> step = 0;  = 0;
		$this-> text = $text;  = $text;
		$this-> delim = $delim; = $delim;
		$this-> maxchars = $maxchars; = $maxchars;
		$this-> draw ();();
	}
 
	public function update ())
	{
		$this-> step ++;++;
		$this-> redraw ();();
	}
 
	private function draw ())
	{
		print $this-> text. ' [';text.' [';
 
		$proc = round (($this-> step / $ this-> steps) *100,0);(($this->step/$this->steps)*100,0);
		$complete = $proc. ' % complete ';.'% complete';
 
		$isuse = strlen ($complete) + 4 + strlen ($this-> text);($complete) + 4 + strlen($this->text);
 
		$max = $this-> maxchars - $isuse;->maxchars - $isuse;
 
		$dash = round ($max * ($ proc/100) +1);($max*($proc/100)+1);
		$free = $max - $dash; - $dash;
 
		if ($dash> 0) print str_repeat ($this-> delim, $dash);>0) print str_repeat($this->delim,$dash);
		if ($free> 0) print str_repeat (' - ', $ free);>0) print str_repeat('-',$free);
		print '] '. $ complete;$complete;
	}
	private function redraw ())
	{
		$this-> toPos ();();
		$this-> draw ();();
	}
	private function toPos ($column = 1)  $column = 1 ) 
	{
	    echo "\033 [{$column} G";G";
	}
}
?>

References where it is possible айти this class:
phpclasses.org

Tags: , , ,

And still I wrote about:
Hurrah! The voting stage has begun.
Хм. Joyful news =)

4 comments → “Console: Progress Bar”


  1. CharnaD

    13 Deck, 2008

    I all wanted at myself on a hosting to make CLI the appendix, and there it is impossible ((

    To answer

  2. Alex Snet

    14 Deck, 2008

    CharnaD, I can offer the.
    ВПС if it is necessary …

    To answer

  3. 0utPunk

    17 Deck, 2008

    There is enough интесный a class, for a long time wished to write itself, yes was not in time) As soon as it is useful, I will try necessarily.

    To answer

  4. Alex Snet

    17 Deck, 2008

    I will be glad, if will help =)

    If that come more often. I will soon lay out сурцы how to process difficult a floor-mat calculations and so on. =). =)

    To answer

To leave the trace.

1 2 3 4 5 6 7 8 9 10