Skip to content

Commit a28b281

Browse files
Copilotswissspidy
andcommitted
Update table wrapping example with documentation
- Add comprehensive examples for all three wrapping modes - Include explanations of when to use each mode - Add usage instructions in the example output - Make executable with proper shebang Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 01d65c7 commit a28b281

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

examples/table-wrapping.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
#!/usr/bin/env php
12
<?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+
*/
29

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();
421

522
// Test data similar to the issue - long plugin names
623
$headers = array('name', 'version', 'update_version', 'status');
@@ -12,16 +29,25 @@
1229
array('short', '1.0', '', 'active'),
1330
);
1431

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();
1637
$table = new \cli\Table();
1738
$table->setHeaders($headers);
1839
$table->setRows($data);
1940
$renderer = new \cli\table\Ascii();
2041
$renderer->setConstraintWidth(70); // Simulate narrower terminal
2142
$table->setRenderer($renderer);
2243
$table->display();
44+
cli\line();
2345

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();
2551
$table = new \cli\Table();
2652
$table->setHeaders($headers);
2753
$table->setRows($data);
@@ -30,8 +56,13 @@
3056
$table->setRenderer($renderer);
3157
$table->setWrappingMode('word-wrap');
3258
$table->display();
59+
cli\line();
3360

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();
3566
$table = new \cli\Table();
3667
$table->setHeaders($headers);
3768
$table->setRows($data);
@@ -40,3 +71,19 @@
4071
$table->setRenderer($renderer);
4172
$table->setWrappingMode('truncate');
4273
$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

Comments
 (0)