fix(cli): preserve table ANSI color across wrapped lines#4050
Conversation
67031df to
1c31a13
Compare
|
E2E report for table inline-code wrap ANSI regression:
Base worktree ( Fixed branch passed: |
| const lines = wrapped.split('\n'); | ||
| const lines = preserveForegroundAcrossLineBreaks(wrapped).split('\n'); | ||
| // Trim trailing empty lines (wrap-ansi artifacts) but preserve internal ones | ||
| while (lines.length > 1 && lines[lines.length - 1]!.length === 0) { |
There was a problem hiding this comment.
[Suggestion] The trailing-empty-line trim here can be defeated by preserveForegroundAcrossLineBreaks.
When a foreground is active and wrapAnsi produces a trailing empty line, preserveForegroundAcrossLineBreaks injects \x1b[39m + the active foreground escape around the trailing \n. The resulting line contains only ANSI codes (e.g. \x1b[38;2;R;G;Bm\x1b[39m), so its .length is non-zero and the while-loop doesn't trim it.
This inflates the line count returned by wrapText, which feeds into calculateMaxRowLines. An inflated count can cause tables to switch from horizontal to vertical format unnecessarily.
stripAnsi is already imported, so the fix is minimal:
| while (lines.length > 1 && lines[lines.length - 1]!.length === 0) { | |
| while (lines.length > 1 && stripAnsi(lines[lines.length - 1]!).length === 0) { |
— glm-5.1 via Qwen Code /review
There was a problem hiding this comment.
Applied as suggested in b5f93c2. Verification trace: when an inline-code span is active at the end of a row, wrapAnsi can emit a trailing \n while the foreground is still open. Walking through preserveForegroundAcrossLineBreaks: the final segment after the last SGR contains text\n, and because activeForeground is set, the \n is rewritten to \x1b[39m\n\${activeForeground}. After split('\n') the trailing element is \${activeForeground} (e.g. \x1b[38;2;R;G;Bm) — .length is 7+, so the old length === 0 check left it in place and calculateMaxRowLines saw an extra line. Switched to stripAnsi(lines[lines.length - 1]!).length === 0; all 47 TableRenderer.test.tsx cases still pass.
| QWEN_TUI_E2E_OUT=/tmp/qwen-table-wrap-ansi/fixed \ | ||
| npx tsx integration-tests/terminal-capture/table-inline-code-wrap-regression.ts | ||
|
|
||
| QWEN_TUI_E2E_REPO=/Users/gawain/Documents/codebase/opensource/qwen-code-table-wrap-ansi-highlight-base \ |
There was a problem hiding this comment.
[Suggestion] The QWEN_TUI_E2E_REPO path is hardcoded to a developer-local directory. Other contributors cannot reproduce these commands as-is.
Consider replacing with a relative path or a placeholder like <path-to-base-worktree> so the E2E test plan is reproducible by anyone.
— glm-5.1 via Qwen Code /review
There was a problem hiding this comment.
Fixed in b5f93c2. The Commands block now starts with FIX_REPO=<path-to-fix-worktree> / BASE_REPO=<path-to-base-worktree> placeholders and the QWEN_TUI_E2E_REPO, cd, and inner cd packages/cli invocations all consume those vars, so anyone with two checkouts (one on this branch, one pinned at the merge-base) can run the plan verbatim.
tanzhenxin
left a comment
There was a problem hiding this comment.
Review
Well-scoped fix at the right seam. The underlying gap is actually upstream in wrap-ansi — its SGR-tracking regex only matches single-parameter codes, so truecolor and 256-color forms aren't re-emitted after a line break. Patching this in the table renderer is correct because Ink doesn't help here (table cells render as flat strings). The post-pass is idempotent with wrap-ansi's native single-parameter carry and composes cleanly with the OSC 8 envelopes in PR #4037. Foreground-only scope is the right call — wrap-ansi already carries bold/italic/underline natively.
Verdict
APPROVE — solid fix with strong evidence.
The initial revert downgraded wrap-ansi to 9.0.2 (the pre-PR-#3860 state). After rebasing onto current main, PR #4050 (preserve table ANSI color across wrapped lines) brought in a new test ("does not preserve foreground after an explicit foreground reset") whose wrap point depends on ink 7's <Text> wrapping behavior. Two-part fix: 1. Restore wrap-ansi to 10 (cli direct dep). The wrap-ansi version is independent of the ink regression we're reverting — wrap-ansi 10 has no peer-dep tie to ink 7 — and #4050's TableRenderer code on main already assumes wrap-ansi 10. Keeping the wrap-ansi bump removes the root override for wrap-ansi (was forcing all transitives to 9.0.2) so cli's TableRenderer gets the wrap-ansi 10 it expects, while ink 6's transitive wrap-ansi naturally resolves to 9 (its own declared range) — no conflict. 2. Skip the one new test that asserts a specific wrap position. The other assertions in that test (foreground cleared, equal visible widths) still pass on ink 6 — only `expectWrappedContinuation` is ink-7-specific. The sibling test 'does not preserve foreground after an explicit reset' (using \\u001b[0m instead of \\u001b[39m) still passes unmodified on ink 6, so the ANSI-handling logic itself is verified end-to-end. The TODO marker references the re-upgrade path. Local verification: - TableRenderer.test.tsx: 54/54 pass + 1 skipped - AppContainer.test.tsx: 61/61 pass - MainContent.test.tsx: 6/6 pass - clearCommand.test.ts: 13/13 pass - npm run typecheck --workspace=packages/cli: clean - npm ls ink → single ink@6.8.0 - npm ls wrap-ansi → cli direct: 10.0.0; ink 6 transitive: 9.0.2 (no conflict, no override) Generated with AI Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
…n from #3860 (#4083) * revert(deps): downgrade ink 7.0.2 → 6.x to fix Static-remount regression from #3860 PR #3860 upgraded ink 6.2.3 → 7.0.2 with the claim of "no business code changes." In production this turns out to break the TUI: - After `/clear`, the next user message and AI response do not render to the static history area — only the dynamic spinner/input area is visible (#3860 + chore/upgrade-ink-7 branch reproduce this). - After Ctrl+O (TOGGLE_COMPACT_MODE), the screen is cleared and stays blank. - Any `refreshStatic()` call path (auth refresh, model change, render- mode switch, /clear, Ctrl+O) puts the UI into the same "muted" state. Root cause is an ink 7 regression: when `<Static>` is remounted by changing its `key` prop, the new instance's items are never written to stdout. A 30-line minimal repro (pure ink + Static + key++) confirms this independently of qwen-code. Closest upstream issue: vadimdemedes/ink#773 (useLayoutEffect-driven child stripping in <Static>). PR #905 ("Fix dangling staticNode reference") merged into ink 7 fixed the unmount-OOM path but not this remount path. No upstream issue yet matches the "remount loses content" case — we should file one and ship a re-upgrade once it is resolved. Scope of this revert (intentional partial revert of #3860): - ink ^7.0.2 → ^6.2.3 (cli + root hoist) - react / react-dom 19.2.4 pin → ^19.1.0 (cli direct, root overrides removed) - wrap-ansi ^10.0.0 → 9.0.2 (cli direct, root override restored) - react-devtools-core kept at ^6.1.5 (still ink-6 compatible — ink 6.8.0's peerOptional requires >=6.1.2; downgrading to 4.x would re-introduce a conflict) - @vitest/eslint-plugin pin "1.3.4" → "^1.3.4" - "@types/node" override removed (was only needed for ink 7's Node 22 type drift) What this revert keeps: - Node engines >=22 across root / cli / core / sdk / web-templates and the matching Dockerfile / .nvmrc / CI matrix work. PR #1876 followed up by adding Node 24 support to the matrix, and rolling those back would conflict with that work. The visible bug is the ink runtime regression, not the engine bump. - doctorChecks.ts MIN_NODE_MAJOR = 22 (matches engines). - The test gating that #3860 added for ink-7 input throttle (AuthDialog / AskUserQuestionDialog / InputPrompt). With ink 6 these tests would pass un-gated, but leaving the gate in place is harmless and a follow-up can un-gate them. Keeping this revert minimal. Verification (local, ink 6.8.0 single instance): - npm ls ink → single ink@6.8.0 - npm ls react → single react@19.2.4 (kept by vscode-ide-companion workspace pin; ink 6 is fine on 19.2) - npm run typecheck --workspace=packages/cli → clean - AppContainer.test.tsx 61/61 pass - MainContent.test.tsx 6/6 pass - clearCommand.test.ts 13/13 pass Re-upgrade path: once ink ships a fix for the Static-remount regression, redo this upgrade behind the feat/virtual-viewport-on-ink7 branch where the `<Static>` + clearTerminal combo is replaced by an overflowY=hidden self-managed viewport. Generated with AI Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * ci(fix): keep wrap-ansi 10 + skip 1 ink-7-specific TableRenderer test The initial revert downgraded wrap-ansi to 9.0.2 (the pre-PR-#3860 state). After rebasing onto current main, PR #4050 (preserve table ANSI color across wrapped lines) brought in a new test ("does not preserve foreground after an explicit foreground reset") whose wrap point depends on ink 7's <Text> wrapping behavior. Two-part fix: 1. Restore wrap-ansi to 10 (cli direct dep). The wrap-ansi version is independent of the ink regression we're reverting — wrap-ansi 10 has no peer-dep tie to ink 7 — and #4050's TableRenderer code on main already assumes wrap-ansi 10. Keeping the wrap-ansi bump removes the root override for wrap-ansi (was forcing all transitives to 9.0.2) so cli's TableRenderer gets the wrap-ansi 10 it expects, while ink 6's transitive wrap-ansi naturally resolves to 9 (its own declared range) — no conflict. 2. Skip the one new test that asserts a specific wrap position. The other assertions in that test (foreground cleared, equal visible widths) still pass on ink 6 — only `expectWrappedContinuation` is ink-7-specific. The sibling test 'does not preserve foreground after an explicit reset' (using \\u001b[0m instead of \\u001b[39m) still passes unmodified on ink 6, so the ANSI-handling logic itself is verified end-to-end. The TODO marker references the re-upgrade path. Local verification: - TableRenderer.test.tsx: 54/54 pass + 1 skipped - AppContainer.test.tsx: 61/61 pass - MainContent.test.tsx: 6/6 pass - clearCommand.test.ts: 13/13 pass - npm run typecheck --workspace=packages/cli: clean - npm ls ink → single ink@6.8.0 - npm ls wrap-ansi → cli direct: 10.0.0; ink 6 transitive: 9.0.2 (no conflict, no override) Generated with AI Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> --------- Co-authored-by: 秦奇 <gary.gq@alibaba-inc.com> Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
| } | ||
|
|
||
| function updateActiveForeground( | ||
| activeForeground: string, |
There was a problem hiding this comment.
[Suggestion] updateActiveForeground only tracks SGR foreground color codes (38, 30-37, 90-97). Format attribute codes produced by renderMarkdownToAnsi — bold (1/22), italic (3/23), underline (4/24), strikethrough (9/29) — are silently ignored. When wrap-ansi breaks a line inside a formatted span (e.g., \x1b[1mBold text that wraps\x1b[22m), updateActiveForeground returns '', so preserveForegroundAcrossLineBreaks does not re-apply bold on the continuation line.
Impact: AI responses with bold, italic, underline, or strikethrough markdown in narrow table cells will lose formatting on wrapped continuation lines. The test suite never exercises this path (all **bold** tests use cell widths that don't trigger wrapping).
| activeForeground: string, | |
| // Extend updateActiveForeground to also track format attributes (codes 1-9, 22-29), | |
| // or document its foreground-only scope. At minimum, add a test with narrow-width | |
| // bold content verifying bold persists on continuation lines. |
— DeepSeek/deepseek-v4-pro via Qwen Code /review
| const foregroundAtText = ( | ||
| output: string, | ||
| text: string, | ||
| ): string | undefined => { |
There was a problem hiding this comment.
[Suggestion] The new wrap-preservation tests only cover truecolor (38;2) and 256-color (38;5) foreground preservation. Standard ANSI color codes 30-37 (red, green, yellow, blue, magenta, cyan, white) and bright foreground codes 90-97 are not tested for wrap preservation, despite being the most commonly used ANSI colors.
A regression in the standard-color branch of updateActiveForeground would not be caught by any test.
| ): string | undefined => { | |
| // Add wrap-preservation tests for standard and bright foreground codes: | |
| // - `\x1b[31mABCDEFGHIJKLMNOPQRSTUVWXYZ\x1b[39m` with narrow width | |
| // - `\x1b[91mABCDEFGHIJKLMNOPQRSTUVWXYZ\x1b[39m` with narrow width | |
| // Assert foregroundAtText on continuation lines returns '31' / '91'. |
— DeepSeek/deepseek-v4-pro via Qwen Code /review
| @@ -245,7 +338,7 @@ function wrapText( | |||
| trim: false, | |||
There was a problem hiding this comment.
[Suggestion] renderRowLines composes three ANSI layers: (1) preserveForegroundAcrossLineBreaks inside wrapText ensures inline colors survive wrapping, (2) recolorAfterResets re-applies base cell color after internal resets, (3) applyColor wraps the entire cell in theme color. The interaction between these — where recolorAfterResets depends on \x1b[39m inserted by preserveForegroundAcrossLineBreaks — is undocumented. A future maintainer who reorders or merges these calls would break ANSI layering with no clear signal why.
| trim: false, | |
| // Add a comment explaining the three-layer ANSI composition and why order matters: | |
| // 1. preserveForegroundAcrossLineBreaks → preserves inline colors across \n | |
| // 2. recolorAfterResets → restores base color after internal \x1b[39m | |
| // 3. applyColor → wraps entire line in theme text color |
— DeepSeek/deepseek-v4-pro via Qwen Code /review
… [upstream cherry-pick] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: 秦奇 <gary.gq@alibaba-inc.com>
…n from #3860 (#4083) * revert(deps): downgrade ink 7.0.2 → 6.x to fix Static-remount regression from #3860 PR #3860 upgraded ink 6.2.3 → 7.0.2 with the claim of "no business code changes." In production this turns out to break the TUI: - After `/clear`, the next user message and AI response do not render to the static history area — only the dynamic spinner/input area is visible (#3860 + chore/upgrade-ink-7 branch reproduce this). - After Ctrl+O (TOGGLE_COMPACT_MODE), the screen is cleared and stays blank. - Any `refreshStatic()` call path (auth refresh, model change, render- mode switch, /clear, Ctrl+O) puts the UI into the same "muted" state. Root cause is an ink 7 regression: when `<Static>` is remounted by changing its `key` prop, the new instance's items are never written to stdout. A 30-line minimal repro (pure ink + Static + key++) confirms this independently of qwen-code. Closest upstream issue: vadimdemedes/ink#773 (useLayoutEffect-driven child stripping in <Static>). PR #905 ("Fix dangling staticNode reference") merged into ink 7 fixed the unmount-OOM path but not this remount path. No upstream issue yet matches the "remount loses content" case — we should file one and ship a re-upgrade once it is resolved. Scope of this revert (intentional partial revert of #3860): - ink ^7.0.2 → ^6.2.3 (cli + root hoist) - react / react-dom 19.2.4 pin → ^19.1.0 (cli direct, root overrides removed) - wrap-ansi ^10.0.0 → 9.0.2 (cli direct, root override restored) - react-devtools-core kept at ^6.1.5 (still ink-6 compatible — ink 6.8.0's peerOptional requires >=6.1.2; downgrading to 4.x would re-introduce a conflict) - @vitest/eslint-plugin pin "1.3.4" → "^1.3.4" - "@types/node" override removed (was only needed for ink 7's Node 22 type drift) What this revert keeps: - Node engines >=22 across root / cli / core / sdk / web-templates and the matching Dockerfile / .nvmrc / CI matrix work. PR #1876 followed up by adding Node 24 support to the matrix, and rolling those back would conflict with that work. The visible bug is the ink runtime regression, not the engine bump. - doctorChecks.ts MIN_NODE_MAJOR = 22 (matches engines). - The test gating that #3860 added for ink-7 input throttle (AuthDialog / AskUserQuestionDialog / InputPrompt). With ink 6 these tests would pass un-gated, but leaving the gate in place is harmless and a follow-up can un-gate them. Keeping this revert minimal. Verification (local, ink 6.8.0 single instance): - npm ls ink → single ink@6.8.0 - npm ls react → single react@19.2.4 (kept by vscode-ide-companion workspace pin; ink 6 is fine on 19.2) - npm run typecheck --workspace=packages/cli → clean - AppContainer.test.tsx 61/61 pass - MainContent.test.tsx 6/6 pass - clearCommand.test.ts 13/13 pass Re-upgrade path: once ink ships a fix for the Static-remount regression, redo this upgrade behind the feat/virtual-viewport-on-ink7 branch where the `<Static>` + clearTerminal combo is replaced by an overflowY=hidden self-managed viewport. Generated with AI Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * ci(fix): keep wrap-ansi 10 + skip 1 ink-7-specific TableRenderer test The initial revert downgraded wrap-ansi to 9.0.2 (the pre-PR-#3860 state). After rebasing onto current main, PR #4050 (preserve table ANSI color across wrapped lines) brought in a new test ("does not preserve foreground after an explicit foreground reset") whose wrap point depends on ink 7's <Text> wrapping behavior. Two-part fix: 1. Restore wrap-ansi to 10 (cli direct dep). The wrap-ansi version is independent of the ink regression we're reverting — wrap-ansi 10 has no peer-dep tie to ink 7 — and #4050's TableRenderer code on main already assumes wrap-ansi 10. Keeping the wrap-ansi bump removes the root override for wrap-ansi (was forcing all transitives to 9.0.2) so cli's TableRenderer gets the wrap-ansi 10 it expects, while ink 6's transitive wrap-ansi naturally resolves to 9 (its own declared range) — no conflict. 2. Skip the one new test that asserts a specific wrap position. The other assertions in that test (foreground cleared, equal visible widths) still pass on ink 6 — only `expectWrappedContinuation` is ink-7-specific. The sibling test 'does not preserve foreground after an explicit reset' (using \\u001b[0m instead of \\u001b[39m) still passes unmodified on ink 6, so the ANSI-handling logic itself is verified end-to-end. The TODO marker references the re-upgrade path. Local verification: - TableRenderer.test.tsx: 54/54 pass + 1 skipped - AppContainer.test.tsx: 61/61 pass - MainContent.test.tsx: 6/6 pass - clearCommand.test.ts: 13/13 pass - npm run typecheck --workspace=packages/cli: clean - npm ls ink → single ink@6.8.0 - npm ls wrap-ansi → cli direct: 10.0.0; ink 6 transitive: 9.0.2 (no conflict, no override) Generated with AI Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> --------- Co-authored-by: 秦奇 <gary.gq@alibaba-inc.com> Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>


Summary
Validation
TableRenderer.test.tsxpassed with 47 tests.chiga0/qwen-code@e8a0a725053314bf5e3399368c1efc134b99ae15onfix/table-wrap-ansi-highlight-artifacts.finalScreenWrappedTableName: true,coloredContinuationOccurrences: 0,uncoloredContinuationOccurrences: 1,pass: false.finalScreenWrappedTableName: true,coloredContinuationOccurrences: 1,uncoloredContinuationOccurrences: 0,pass: true.Scope / Risk
Testing Matrix
Testing matrix notes:
Linked Issues / Bugs
Fixes #4052