Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Summary

This PR implements configurable wrapping modes for table cells to address the issue where long text (like plugin names) is split at awkward character boundaries, making it difficult to copy and paste.

Changes

  • Add three wrapping modes to Ascii renderer:
    • wrap (default): Character-boundary wrapping (preserves backward compatibility)
    • word-wrap: Word-boundary wrapping (splits at spaces/hyphens)
    • truncate: Truncates with ellipsis (...)
  • Add setWrappingMode() method to Table and Ascii classes
  • Implement helper methods wrapText() and wordWrap()
  • Add comprehensive unit tests
  • Add example demonstrating all three modes
  • Pass all existing tests (backward compatible)
  • Pass code review and security checks
  • Refactor based on code review feedback:
    • Use class constant for valid wrapping modes
    • Optimize width tracking in wordWrap()
    • Add ellipsis constants for better maintainability
    • Simplify pre-colorized condition check

Usage Example

$table = new \cli\Table();
$table->setHeaders($headers);
$table->setRows($data);
$table->setWrappingMode('word-wrap'); // or 'truncate'
$table->display();

Visual Comparison

Before (character-boundary):

| all-in-one-wp-migration-mult | 4.34    | inactive |
| isite-extension              |         |          |

❌ Splits mid-word, hard to copy

With word-wrap:

| all-in-one-wp-migration-     | 4.34    | inactive |
| multisite-extension          |         |          |

✅ Keeps words intact, easy to copy

With truncate:

| all-in-one-wp-migration-m... | 4.34    | inactive |

✅ Compact single-line display

Security Summary

No security vulnerabilities detected. All code changes are focused on text formatting logic with proper input validation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Wordwrapping in the tabular output</issue_title>
<issue_description>Hi there,

This is either a feature request or a support request, depending on whether the functionality I'm seeking exists.

In my terminal, whose usual dimensions are the standard 80x24, when I list things like plugins, I get output like that below:

$ wp plugin list --fields=name,version,update_version,status

+-----------------------+--------------------------+----------------+----------+
| name                  | version                  | update_version | status   |
+-----------------------+--------------------------+----------------+----------+
| advanced-custom-field | 6.2.7                    |                | active   |
| s                     |                          |                |          |
| advanced-query-loop   | 2.1.1                    |                | active   |
| all-in-one-wp-migrati | 7.81                     |                | inactive |
| on                    |                          |                |          |
| all-in-one-wp-migrati | 4.34                     |                | inactive |
| on-multisite-extensio |                          |                |          |
| n                     |                          |                |          |
+-----------------------+--------------------------+----------------+----------+

As you can see, the plugin names wrap onto multiple lines. I sometimes wish to copy and paste the names, but the line wrapping interferes with this. I know I can 1) widen my terminal and re-run the command or 2) pipe the output to a file (which strips the columnar formatting), but I'm wondering if there is a way to either...

  • display the content like the mysql client does, wrapping over lines but never in columns when the width of the content exceeds the terminal width.
  • or explicitly set the width of a given column or columns (even if that truncates some content).

I think "mysql client behavior" might be useful for more than just me.

Thanks for sharing your thoughts.

Saul</issue_description>

Comments on the Issue (you are @copilot in this section)

@swissspidy Related:

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add setWrappingMode() method to Ascii renderer and Table class
- Support three modes: 'wrap' (default), 'word-wrap', and 'truncate'
- word-wrap mode wraps at word boundaries (spaces/hyphens)
- truncate mode truncates with ellipsis (...)
- Add helper methods wrapText() and wordWrap() for wrapping logic
- Add tests for new functionality

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/cli/table/Ascii.php 78.94% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

- 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>
Copilot AI changed the title [WIP] Fix wordwrapping in the tabular output Add configurable wrapping modes for table columns Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 18:37
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

…dth tracking

- Define VALID_WRAPPING_MODES as a private class constant for better maintainability
- Optimize wordWrap() by tracking width incrementally instead of recalculating Colors::width() on every iteration
- Addresses code review feedback from @swissspidy

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

- Define ELLIPSIS and ELLIPSIS_WIDTH as class constants for better maintainability
- Remove redundant width check in pre-colorized condition (already validated earlier)
- Addresses code review feedback from @swissspidy

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review February 3, 2026 16:14
@swissspidy swissspidy requested a review from a team as a code owner February 3, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wordwrapping in the tabular output

2 participants