Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

  • Explore repository structure and understand the codebase
  • Identify the issue in Ascii.php row() method (lines 144-164)
  • Reproduce the issue with a test case
  • Add helper functions to extract and restore color state from strings
  • Modify the wrapping logic to preserve color codes across wrapped lines
  • Add tests for wrapped colorized table cells
  • Run existing tests to ensure no regressions
  • Verify the fix with manual testing
  • Remove obsolete getActiveColor function
Original prompt

This section details on the original issue you should resolve

<issue_title>Wrapped lines in table view break colorization</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

When using WP_CLI::colorize() for values that are to be displayed in a table, the line wrapping breaks the colorization and the calculated line length.

Image 2019-12-16 at 2 36 56 PM

Describe what you expect as the correct outcome

The table formatting should be aware of colorization (as it already has an optional argument to denote pre-colorized content) and adapt the color codes when it manipulates the strings.

Provide a possible solution

The formatting code should:

  • terminate the left part with a %n and prefix the right part with the color code that was active when detecting a colorized string it needs to break up for wrapping.
  • take the manipulated color codes into account for each single line when calculating the column length.</issue_description>

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


💡 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.

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

This comment was marked as resolved.

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

This comment was marked as resolved.

@swissspidy swissspidy changed the title [WIP] Fix line wrapping issue with colorized table output Fix line wrapping issue with colorized table output Jan 19, 2026
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy

This comment was marked as resolved.

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

This comment was marked as resolved.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where ANSI color codes in table cells are not properly preserved when text wraps across multiple lines, causing broken colorization and incorrect width calculations.

Changes:

  • Added wrapPreColorized() method to handle color-aware text wrapping
  • Modified table row rendering to use the new wrapping function for pre-colorized content
  • Added comprehensive test coverage for wrapped colorized table cells

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/cli/Colors.php Adds getResetCode() and wrapPreColorized() methods to preserve ANSI color codes across wrapped lines
lib/cli/table/Ascii.php Updates row rendering logic to use color-aware wrapping for pre-colorized content
tests/Test_Table_Ascii.php Adds test case verifying that colorized text maintains color codes when wrapped

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if ( preg_match( '/\x1b\[0m/', $part ) ) {
// Reset code
$active_color = '';
} elseif ( preg_match( '/\x1b\[([0-9;]+)m/', $part, $matches ) && $matches[1] !== '0' ) {
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition $matches[1] !== '0' uses strict string comparison, but the check for reset codes on line 325 uses a regex pattern. This inconsistency could miss some edge cases. Additionally, this only tracks the most recent color code, which doesn't account for layered formatting (e.g., bold + color). Consider tracking all active formatting codes or documenting this limitation.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

Wrapped lines in table view break colorization

2 participants