Las bromas las anécdotas

Console: Progress Bar

Del diciembre 10, 2008 · 3:21 дп Alex Snet  -  4 comentarios


Continuando el tema de la consola …

El progreso-bar simple en пхп … =)

¿<?
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. ' DEL % 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";
	}
}
?>

Las referencias, donde es posible айти esta clase:
phpclasses.org

Тэги: , , ,

А todavía escribía sobre:
¡Hurra! Ha comenzado la etapa de la votación.
Hum. La novedad alegre =)

4 comentarios → “Console: Progress Bar”


  1. CharnaD

    13 Puente, 2008

    Todo quería sobre el alojamiento hacer CLI la aplicación, а no es posible allí ((

    Responder

  2. Alex Snet

    14 Puente, 2008

    CharnaD, puedo proponer.
    ВПС, si es necesario …

    Responder

  3. 0utPunk

    17 Puente, 2008

    Bastante интесный la clase, hace mucho quería escribir, sí no ha llegado a tiempo) Tan pronto como es útil, probaré obligatoriamente.

    Responder

  4. Alex Snet

    17 Puente, 2008

    Seré contento, si ayuda =)

    Si que, pasáis más a menudo. Pondré Pronto сурцы como tratar difícil el mate los cálculos etcétera. =). =)

    Responder

Dejar la huella.

1 2 3 4 5 6 7 8 9 10