-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathprogress-step-format.php
More file actions
60 lines (52 loc) · 1.29 KB
/
progress-step-format.php
File metadata and controls
60 lines (52 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require_once 'common.php';
// 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++) {
$progress->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();