-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathincremental-table.php
More file actions
84 lines (66 loc) · 2.3 KB
/
incremental-table.php
File metadata and controls
84 lines (66 loc) · 2.3 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once 'common.php';
/**
* Example demonstrating the incremental table row display feature.
* This shows how to display a table header once and then add rows incrementally in a loop.
*/
echo "Example 1: Using displayRow() to add rows incrementally\n";
echo "=========================================================\n\n";
$table = new \cli\Table();
$table->setHeaders(array('File Name', 'Status', 'Progress'));
$table->display();
// Simulate processing items in a loop
$items = array(
array('file1.txt', 'Done', '100%'),
array('file2.txt', 'Done', '100%'),
array('file3.txt', 'Done', '100%'),
array('file4.txt', 'Done', '100%'),
);
foreach ($items as $item) {
// Add some delay to simulate processing
usleep(200000); // 0.2 seconds
$table->displayRow($item);
}
echo "\n\nExample 2: Using resetRows() with incremental display\n";
echo "========================================================\n\n";
$table2 = new \cli\Table();
$table2->setHeaders(array('Name', 'Age', 'City'));
$table2->display();
echo "Adding first batch of rows...\n";
$table2->displayRow(array('Alice', '30', 'New York'));
$table2->displayRow(array('Bob', '25', 'London'));
echo "\nClearing rows and adding new batch...\n";
$table2->resetRows();
$table2->displayRow(array('Charlie', '35', 'Paris'));
$table2->displayRow(array('Diana', '28', 'Tokyo'));
echo "\n\nExample 3: Real-time progress display\n";
echo "========================================\n\n";
$table3 = new \cli\Table();
$table3->setHeaders(array('Task', 'Result'));
$table3->display();
$tasks = array(
array('Initialize database', 'OK'),
array('Load configuration', 'OK'),
array('Connect to API', 'OK'),
array('Process data', 'OK'),
array('Generate report', 'OK'),
);
foreach ($tasks as $task) {
usleep(300000); // 0.3 seconds
$table3->displayRow($task);
}
echo "\n\nExample 4: Tabular format (for piped output)\n";
echo "==============================================\n\n";
$table4 = new \cli\Table();
$table4->setRenderer(new \cli\table\Tabular());
$table4->setHeaders(array('ID', 'Name', 'Email'));
$table4->display();
$users = array(
array('1', 'John Doe', 'john@example.com'),
array('2', 'Jane Smith', 'jane@example.com'),
array('3', 'Bob Johnson', 'bob@example.com'),
);
foreach ($users as $user) {
usleep(100000); // 0.1 seconds
$table4->displayRow($user);
}