Zend_Console_ProgessBar in Incubator

Tuesday, August 19, 2008

I was bored the other day again, and thought about some tiny component, which would be as well helpful for some other developers. And there the idea came: Console applications need to show the status somehow, and what is a better way than a progressbar? Well, without telling much, you can kinda simply test it out yourself. Get Zend/Console/ProgressBar.php from the Incubator, and use the following test code:
<?php
require_once 'Zend/Console/ProgressBar.php';

fwrite(STDOUT, "Please wait, while I sleep:\n");

$progressBar = new Zend_Console_ProgressBar();
for ($i = 1; $i <= 100; $i++) {
    $progressBar->update($i);
    usleep(1000000);
}

fwrite(STDOUT, "\n");
The result of that code will somewhat look like this:



If you have any further improvements you want in this component, just tell me.

Features:
- Custom min/max values
- Custom order of elements (percent, ETA, bar) as well as leaving out elements
- Automatic ETA calculation
- Automatic window width calculation

Comments to this article

  • Avatar of bpat1434 Reply bpat1434 Monday, August 25, 2008 6:21 PM

    Would be neat to be able to customize the marker in the bar. So instead of having:

    [#####-----------------------------------------]

    we could maybe use
    |-----[]-------------------------------------------|
    or
    [------> ]

  • Avatar of Ben 'DASPRiD' Scholzen Reply Ben 'DASPRiD' Scholzen Monday, August 25, 2008 8:33 PM

    That's in fact a very nice idea. You could define "left-hand character", "marker character" and "right-hand character". I'm going to implemented this.

Leave a comment

Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and for notifications.

     _                            
  __| | ___   __ _  __ _  ___ ___ 
 / _` |/ _ \ / _` |/ _` |/ __/ _ \
| (_| | (_) | (_| | (_| | (_|  __/
 \__,_|\___/ \__, |\__,_|\___\___|
                |_|