From 8e5b3da0a73f4f1ccf04da53ea9f4eb74b211cdd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 01:59:02 +0000 Subject: [PATCH 1/6] Initial plan From eaf01ab2944ca816b1340d47e5d8522e371d7391 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 02:05:51 +0000 Subject: [PATCH 2/6] Add format parameters and current/total placeholders to Bar progress Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- lib/cli/progress/Bar.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/cli/progress/Bar.php b/lib/cli/progress/Bar.php index e800509..c6d2342 100644 --- a/lib/cli/progress/Bar.php +++ b/lib/cli/progress/Bar.php @@ -31,6 +31,30 @@ class Bar extends Progress { protected $_formatTiming = '] {:elapsed} / {:estimated}'; protected $_format = '{:msg}{:bar}{:timing}'; + /** + * Instantiates a Progress Bar. + * + * @param string $msg The text to display next to the Notifier. + * @param int $total The total number of ticks we will be performing. + * @param int $interval The interval in milliseconds between updates. + * @param string $formatMessage Optional format string for the message portion. + * @param string $formatTiming Optional format string for the timing portion. + * @param string $format Optional format string for the overall display. + */ + public function __construct($msg, $total, $interval = 100, $formatMessage = null, $formatTiming = null, $format = null) { + parent::__construct($msg, $total, $interval); + + if ($formatMessage !== null) { + $this->_formatMessage = $formatMessage; + } + if ($formatTiming !== null) { + $this->_formatTiming = $formatTiming; + } + if ($format !== null) { + $this->_format = $format; + } + } + /** * Prints the progress bar to the screen with percent complete, elapsed time * and estimated total time. @@ -49,7 +73,9 @@ public function display($finish = false) { $percent = str_pad(floor($_percent * 100), 3); $msg = $this->_message; - $msg = Streams::render($this->_formatMessage, compact('msg', 'percent')); + $current = $this->current(); + $total = $this->total(); + $msg = Streams::render($this->_formatMessage, compact('msg', 'percent', 'current', 'total')); $estimated = $this->formatTime($this->estimated()); $elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated)); From 51707d4ebb5162a2b58863d51262874c733b4704 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 02:06:56 +0000 Subject: [PATCH 3/6] Fix trailing whitespace and add example file Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- examples/progress-step-format.php | 60 +++++++++++++++++++++++++++++++ lib/cli/progress/Bar.php | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 examples/progress-step-format.php diff --git a/examples/progress-step-format.php b/examples/progress-step-format.php new file mode 100644 index 0000000..f49ca10 --- /dev/null +++ b/examples/progress-step-format.php @@ -0,0 +1,60 @@ +tick(); + usleep(100000); +} +$progress->finish(); + +echo "\n"; + +// Example 2: Step-based format (current/total) +echo "Example 2: Step-based format (current/total)\n"; +$progress = new \cli\progress\Bar( + 'Step format', + 10, + 100, + '{:msg} {:current}/{:total} [' // Custom formatMessage with current/total +); +for ($i = 0; $i <= 10; $i++) { + $progress->tick(); + usleep(100000); +} +$progress->finish(); + +echo "\n"; + +// Example 3: Custom format combining steps and percentage +echo "Example 3: Custom format combining steps and percentage\n"; +$progress = new \cli\progress\Bar( + 'Mixed format', + 50, + 100, + '{:msg} {:current}/{:total} ({:percent}%) [' // Both current/total and percent +); +for ($i = 0; $i <= 50; $i++) { + $progress->tick(); + usleep(50000); +} +$progress->finish(); + +echo "\n"; + +// Example 4: Large numbers with step format +echo "Example 4: Large numbers with step format\n"; +$progress = new \cli\progress\Bar( + 'Processing items', + 1000, + 100, + '{:msg} {:current}/{:total} [' +); +for ($i = 0; $i <= 1000; $i += 50) { + $progress->tick(50); + usleep(20000); +} +$progress->finish(); diff --git a/lib/cli/progress/Bar.php b/lib/cli/progress/Bar.php index c6d2342..9a99568 100644 --- a/lib/cli/progress/Bar.php +++ b/lib/cli/progress/Bar.php @@ -43,7 +43,7 @@ class Bar extends Progress { */ public function __construct($msg, $total, $interval = 100, $formatMessage = null, $formatTiming = null, $format = null) { parent::__construct($msg, $total, $interval); - + if ($formatMessage !== null) { $this->_formatMessage = $formatMessage; } From 0d8644d53bf87e3ae8f1f03065885491eabe15dd Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Feb 2026 22:19:19 -0500 Subject: [PATCH 4/6] Update lib/cli/progress/Bar.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/cli/progress/Bar.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cli/progress/Bar.php b/lib/cli/progress/Bar.php index 9a99568..7fe04f3 100644 --- a/lib/cli/progress/Bar.php +++ b/lib/cli/progress/Bar.php @@ -34,12 +34,12 @@ class Bar extends Progress { /** * Instantiates a Progress Bar. * - * @param string $msg The text to display next to the Notifier. - * @param int $total The total number of ticks we will be performing. - * @param int $interval The interval in milliseconds between updates. - * @param string $formatMessage Optional format string for the message portion. - * @param string $formatTiming Optional format string for the timing portion. - * @param string $format Optional format string for the overall display. + * @param string $msg The text to display next to the Notifier. + * @param int $total The total number of ticks we will be performing. + * @param int $interval The interval in milliseconds between updates. + * @param string|null $formatMessage Optional format string for the message portion. + * @param string|null $formatTiming Optional format string for the timing portion. + * @param string|null $format Optional format string for the overall display. */ public function __construct($msg, $total, $interval = 100, $formatMessage = null, $formatTiming = null, $format = null) { parent::__construct($msg, $total, $interval); From 5ca8c01f7c7a1a508768e44a39b5c3d1d9ffb305 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Feb 2026 22:19:31 -0500 Subject: [PATCH 5/6] Update examples/progress-step-format.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- examples/progress-step-format.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/progress-step-format.php b/examples/progress-step-format.php index f49ca10..c565f8e 100644 --- a/examples/progress-step-format.php +++ b/examples/progress-step-format.php @@ -53,7 +53,7 @@ 100, '{:msg} {:current}/{:total} [' ); -for ($i = 0; $i <= 1000; $i += 50) { +for ($i = 0; $i < 1000; $i += 50) { $progress->tick(50); usleep(20000); } From 568d46c0dda2300f305c556b99d2b6c2c9a1f143 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:30:22 +0000 Subject: [PATCH 6/6] Fix loop bounds and add placeholders to all format strings Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- examples/progress-step-format.php | 6 +++--- lib/cli/progress/Bar.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/progress-step-format.php b/examples/progress-step-format.php index c565f8e..a79965d 100644 --- a/examples/progress-step-format.php +++ b/examples/progress-step-format.php @@ -5,7 +5,7 @@ // Example 1: Default percentage-based format echo "Example 1: Default percentage-based format\n"; $progress = new \cli\progress\Bar('Default format', 10); -for ($i = 0; $i <= 10; $i++) { +for ($i = 0; $i < 10; $i++) { $progress->tick(); usleep(100000); } @@ -21,7 +21,7 @@ 100, '{:msg} {:current}/{:total} [' // Custom formatMessage with current/total ); -for ($i = 0; $i <= 10; $i++) { +for ($i = 0; $i < 10; $i++) { $progress->tick(); usleep(100000); } @@ -37,7 +37,7 @@ 100, '{:msg} {:current}/{:total} ({:percent}%) [' // Both current/total and percent ); -for ($i = 0; $i <= 50; $i++) { +for ($i = 0; $i < 50; $i++) { $progress->tick(); usleep(50000); } diff --git a/lib/cli/progress/Bar.php b/lib/cli/progress/Bar.php index 7fe04f3..43f21b5 100644 --- a/lib/cli/progress/Bar.php +++ b/lib/cli/progress/Bar.php @@ -79,7 +79,7 @@ public function display($finish = false) { $estimated = $this->formatTime($this->estimated()); $elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated)); - $timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated')); + $timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated', 'current', 'total', 'percent')); $size = Shell::columns(); $size -= strlen($msg . $timing); @@ -91,7 +91,7 @@ public function display($finish = false) { // substr is needed to trim off the bar cap at 100% $bar = substr(str_pad($bar, $size, ' '), 0, $size); - Streams::out($this->_format, compact('msg', 'bar', 'timing')); + Streams::out($this->_format, compact('msg', 'bar', 'timing', 'current', 'total', 'percent')); } /**