|
11 | 11 | echo "=========================================================\n\n"; |
12 | 12 |
|
13 | 13 | $table = new \cli\Table(); |
14 | | -$table->setHeaders(array('Item', 'Status', 'Progress')); |
| 14 | +$table->setHeaders(array('File Name', 'Status', 'Progress')); |
15 | 15 | $table->display(); |
16 | 16 |
|
17 | 17 | // Simulate processing items in a loop |
18 | 18 | $items = array( |
19 | | - array('Processing file 1', 'Done', '100%'), |
20 | | - array('Processing file 2', 'Done', '100%'), |
21 | | - array('Processing file 3', 'Done', '100%'), |
22 | | - array('Processing file 4', 'Done', '100%'), |
| 19 | + array('file1.txt', 'Done', '100%'), |
| 20 | + array('file2.txt', 'Done', '100%'), |
| 21 | + array('file3.txt', 'Done', '100%'), |
| 22 | + array('file4.txt', 'Done', '100%'), |
23 | 23 | ); |
24 | 24 |
|
25 | 25 | foreach ($items as $item) { |
|
28 | 28 | $table->displayRow($item); |
29 | 29 | } |
30 | 30 |
|
31 | | -echo "\n\nExample 2: Using resetRows() to clear and update table data\n"; |
32 | | -echo "==============================================================\n\n"; |
| 31 | +echo "\n\nExample 2: Using resetRows() with incremental display\n"; |
| 32 | +echo "========================================================\n\n"; |
33 | 33 |
|
34 | 34 | $table2 = new \cli\Table(); |
35 | 35 | $table2->setHeaders(array('Name', 'Age', 'City')); |
36 | | -$table2->addRow(array('Alice', '30', 'New York')); |
37 | | -$table2->addRow(array('Bob', '25', 'London')); |
38 | 36 | $table2->display(); |
39 | 37 |
|
40 | | -echo "\nClearing rows and adding new data...\n\n"; |
| 38 | +echo "Adding first batch of rows...\n"; |
| 39 | +$table2->displayRow(array('Alice', '30', 'New York')); |
| 40 | +$table2->displayRow(array('Bob', '25', 'London')); |
41 | 41 |
|
| 42 | +echo "\nClearing rows and adding new batch...\n"; |
42 | 43 | $table2->resetRows(); |
43 | | -$table2->addRow(array('Charlie', '35', 'Paris')); |
44 | | -$table2->addRow(array('Diana', '28', 'Tokyo')); |
45 | | -$table2->display(); |
| 44 | +$table2->displayRow(array('Charlie', '35', 'Paris')); |
| 45 | +$table2->displayRow(array('Diana', '28', 'Tokyo')); |
46 | 46 |
|
47 | | -echo "\n\nExample 3: Incremental display with Tabular renderer (for piped output)\n"; |
48 | | -echo "========================================================================\n\n"; |
| 47 | +echo "\n\nExample 3: Real-time progress display\n"; |
| 48 | +echo "========================================\n\n"; |
49 | 49 |
|
50 | 50 | $table3 = new \cli\Table(); |
51 | | -$table3->setRenderer(new \cli\table\Tabular()); |
52 | | -$table3->setHeaders(array('ID', 'Name', 'Email')); |
| 51 | +$table3->setHeaders(array('Task', 'Result')); |
53 | 52 | $table3->display(); |
54 | 53 |
|
| 54 | +$tasks = array( |
| 55 | + array('Initialize database', 'OK'), |
| 56 | + array('Load configuration', 'OK'), |
| 57 | + array('Connect to API', 'OK'), |
| 58 | + array('Process data', 'OK'), |
| 59 | + array('Generate report', 'OK'), |
| 60 | +); |
| 61 | + |
| 62 | +foreach ($tasks as $task) { |
| 63 | + usleep(300000); // 0.3 seconds |
| 64 | + $table3->displayRow($task); |
| 65 | +} |
| 66 | + |
| 67 | +echo "\n\nExample 4: Tabular format (for piped output)\n"; |
| 68 | +echo "==============================================\n\n"; |
| 69 | + |
| 70 | +$table4 = new \cli\Table(); |
| 71 | +$table4->setRenderer(new \cli\table\Tabular()); |
| 72 | +$table4->setHeaders(array('ID', 'Name', 'Email')); |
| 73 | +$table4->display(); |
| 74 | + |
55 | 75 | $users = array( |
56 | 76 | array('1', 'John Doe', 'john@example.com'), |
57 | 77 | array('2', 'Jane Smith', 'jane@example.com'), |
|
60 | 80 |
|
61 | 81 | foreach ($users as $user) { |
62 | 82 | usleep(100000); // 0.1 seconds |
63 | | - $table3->displayRow($user); |
| 83 | + $table4->displayRow($user); |
64 | 84 | } |
0 commit comments