Skip to content

Commit 51707d4

Browse files
Copilotswissspidy
andcommitted
Fix trailing whitespace and add example file
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent eaf01ab commit 51707d4

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

examples/progress-step-format.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
require_once 'common.php';
4+
5+
// Example 1: Default percentage-based format
6+
echo "Example 1: Default percentage-based format\n";
7+
$progress = new \cli\progress\Bar('Default format', 10);
8+
for ($i = 0; $i <= 10; $i++) {
9+
$progress->tick();
10+
usleep(100000);
11+
}
12+
$progress->finish();
13+
14+
echo "\n";
15+
16+
// Example 2: Step-based format (current/total)
17+
echo "Example 2: Step-based format (current/total)\n";
18+
$progress = new \cli\progress\Bar(
19+
'Step format',
20+
10,
21+
100,
22+
'{:msg} {:current}/{:total} [' // Custom formatMessage with current/total
23+
);
24+
for ($i = 0; $i <= 10; $i++) {
25+
$progress->tick();
26+
usleep(100000);
27+
}
28+
$progress->finish();
29+
30+
echo "\n";
31+
32+
// Example 3: Custom format combining steps and percentage
33+
echo "Example 3: Custom format combining steps and percentage\n";
34+
$progress = new \cli\progress\Bar(
35+
'Mixed format',
36+
50,
37+
100,
38+
'{:msg} {:current}/{:total} ({:percent}%) [' // Both current/total and percent
39+
);
40+
for ($i = 0; $i <= 50; $i++) {
41+
$progress->tick();
42+
usleep(50000);
43+
}
44+
$progress->finish();
45+
46+
echo "\n";
47+
48+
// Example 4: Large numbers with step format
49+
echo "Example 4: Large numbers with step format\n";
50+
$progress = new \cli\progress\Bar(
51+
'Processing items',
52+
1000,
53+
100,
54+
'{:msg} {:current}/{:total} ['
55+
);
56+
for ($i = 0; $i <= 1000; $i += 50) {
57+
$progress->tick(50);
58+
usleep(20000);
59+
}
60+
$progress->finish();

lib/cli/progress/Bar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Bar extends Progress {
4343
*/
4444
public function __construct($msg, $total, $interval = 100, $formatMessage = null, $formatTiming = null, $format = null) {
4545
parent::__construct($msg, $total, $interval);
46-
46+
4747
if ($formatMessage !== null) {
4848
$this->_formatMessage = $formatMessage;
4949
}

0 commit comments

Comments
 (0)