|
| 1 | +#!/usr/bin/env php |
1 | 2 | <?php |
| 3 | +/** |
| 4 | + * Table Wrapping Mode Examples |
| 5 | + * |
| 6 | + * This example demonstrates the table cell wrapping feature. |
| 7 | + * You can control how long content is wrapped in table cells. |
| 8 | + */ |
2 | 9 |
|
3 | | -require_once 'common.php'; |
| 10 | +if (file_exists(__DIR__ . '/../vendor/autoload.php')) { |
| 11 | + require_once __DIR__ . '/../vendor/autoload.php'; |
| 12 | +} elseif (file_exists(__DIR__ . '/../../../autoload.php')) { |
| 13 | + require_once __DIR__ . '/../../../autoload.php'; |
| 14 | +} else { |
| 15 | + throw new Exception('Unable to locate autoloader; please run "composer install"'); |
| 16 | +} |
| 17 | + |
| 18 | +cli\line(); |
| 19 | +cli\line('%G===%n %CTable Wrapping Mode Examples%n %G===%n'); |
| 20 | +cli\line(); |
4 | 21 |
|
5 | 22 | // Test data similar to the issue - long plugin names |
6 | 23 | $headers = array('name', 'version', 'update_version', 'status'); |
|
12 | 29 | array('short', '1.0', '', 'active'), |
13 | 30 | ); |
14 | 31 |
|
15 | | -echo "=== Default wrapping (character boundaries) ===\n"; |
| 32 | +// Example 1: Default wrapping (character boundaries) |
| 33 | +cli\line('%Y## Example 1: Default Wrapping (Character Boundaries)%n'); |
| 34 | +cli\line('The default behavior wraps text at character boundaries when it'); |
| 35 | +cli\line('exceeds the column width. This can split words in awkward places.'); |
| 36 | +cli\line(); |
16 | 37 | $table = new \cli\Table(); |
17 | 38 | $table->setHeaders($headers); |
18 | 39 | $table->setRows($data); |
19 | 40 | $renderer = new \cli\table\Ascii(); |
20 | 41 | $renderer->setConstraintWidth(70); // Simulate narrower terminal |
21 | 42 | $table->setRenderer($renderer); |
22 | 43 | $table->display(); |
| 44 | +cli\line(); |
23 | 45 |
|
24 | | -echo "\n=== Word-wrap mode (wrap at word boundaries) ===\n"; |
| 46 | +// Example 2: Word-wrap mode (wrap at word boundaries) |
| 47 | +cli\line('%Y## Example 2: Word-Wrap Mode (Wrap at Word Boundaries)%n'); |
| 48 | +cli\line('Word-wrap mode keeps words together by wrapping at spaces and hyphens.'); |
| 49 | +cli\line('This makes it easier to read and copy/paste long values.'); |
| 50 | +cli\line(); |
25 | 51 | $table = new \cli\Table(); |
26 | 52 | $table->setHeaders($headers); |
27 | 53 | $table->setRows($data); |
|
30 | 56 | $table->setRenderer($renderer); |
31 | 57 | $table->setWrappingMode('word-wrap'); |
32 | 58 | $table->display(); |
| 59 | +cli\line(); |
33 | 60 |
|
34 | | -echo "\n=== Truncate mode (truncate with ellipsis) ===\n"; |
| 61 | +// Example 3: Truncate mode (truncate with ellipsis) |
| 62 | +cli\line('%Y## Example 3: Truncate Mode (Truncate with Ellipsis)%n'); |
| 63 | +cli\line('Truncate mode cuts off long content and adds "..." to indicate truncation.'); |
| 64 | +cli\line('This is useful when you want a compact display and don\'t need full values.'); |
| 65 | +cli\line(); |
35 | 66 | $table = new \cli\Table(); |
36 | 67 | $table->setHeaders($headers); |
37 | 68 | $table->setRows($data); |
|
40 | 71 | $table->setRenderer($renderer); |
41 | 72 | $table->setWrappingMode('truncate'); |
42 | 73 | $table->display(); |
| 74 | +cli\line(); |
| 75 | + |
| 76 | +// Example 4: Usage instructions |
| 77 | +cli\line('%Y## Wrapping Mode Options%n'); |
| 78 | +cli\line(); |
| 79 | +cli\line('You can use the following wrapping modes:'); |
| 80 | +cli\line(' %G*%n %Cwrap%n - Default: wrap at character boundaries'); |
| 81 | +cli\line(' %G*%n %Cword-wrap%n - Wrap at word boundaries (spaces/hyphens)'); |
| 82 | +cli\line(' %G*%n %Ctruncate%n - Truncate with ellipsis (...)'); |
| 83 | +cli\line(); |
| 84 | +cli\line('Example usage:'); |
| 85 | +cli\line(' %c$table->setWrappingMode(\'word-wrap\');%n'); |
| 86 | +cli\line(); |
| 87 | + |
| 88 | +cli\line('%GDone!%n'); |
| 89 | +cli\line(); |
0 commit comments