Last active
March 24, 2023 15:37
-
-
Save rodrigoslayertech/5129f053a778e3b9b495fb2fceee94bb to your computer and use it in GitHub Desktop.
Bootgly CLI vs Symfony Console - Progress Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bootgly\CLI; | |
use Bootgly\CLI; | |
use Bootgly\CLI\Terminal\components\Progress; | |
$Output = CLI::$Terminal->Output; | |
$Output->reset(); | |
$Output->render(<<<OUTPUT | |
/* @* | |
* @#green: Bootgly CLI Terminal - Progress component @; | |
* @#yellow: Example #1: {$example} @; | |
* Love Bootgly? Give our repo a star ⭐! | |
*/\n\n | |
OUTPUT); | |
$Progress = new Progress($Output); | |
// * Config | |
// @ Ticks | |
$Progress->ticks = 250000; | |
$Progress->throttle = 0; | |
// @ Templating | |
$Progress->template = <<<'TEMPLATE' | |
@description; | |
@ticked;/@ticks; [@bar;] @percent;% | |
⏱️ @elapsed;s - 🏁 @eta;s - 📈 @rate; loops/s | |
TEMPLATE; | |
// ! Bar | |
// Symbols | |
$Progress->Bar->symbols = [ | |
'determined' => [ | |
// Symbols array map: | |
// 0 => incomplete / 1 => current / 2 => complete | |
'🖤', '', '❤️' | |
], | |
'indetermined' => ['-'] | |
]; | |
// Units | |
$Progress->Bar->units = 10; | |
$Progress->start(); | |
$i = 0; | |
while ($i++ < 250000) { | |
if ($i === 1) { | |
$Progress->describe('@#red:Performing progress! @;'); | |
} | |
if ($i === 125000) { | |
$Progress->describe('@#yellow:There\'s only half left... @;'); | |
} | |
if ($i === 249999) { | |
$Progress->describe('@#green:Finished!!! @;'); | |
} | |
$Progress->tick(); | |
} | |
$Progress->finish(); | |
// Symfony source-code: | |
// https://gist.github.com/rodrigoslayertech/b12804d5a0c76adbf1c5272d8396618b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment