fix(tui): resolve shell carriage-return redraws#1548
Conversation
🦋 Changeset detectedLatest commit: ff70fc9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99f5dc7c2c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| .replace(CSI_PATTERN, '') | ||
| .replace(ESC_SINGLE_PATTERN, '') | ||
| .replace(C0_CONTROL_PATTERN, ''); | ||
| .replace(ESC_SINGLE_PATTERN, ''); | ||
| return resolveCarriageReturns(withoutEscapes).replace(C0_CONTROL_PATTERN, ''); |
There was a problem hiding this comment.
Honor erase-in-line when resolving carriage returns
For redraws that clear the current line, such as Downloading 100%\rDone\u001b[K or Downloading 100%\r\u001b[KDone, this strips ESC[K before simulating the carriage return, so resolveCarriageReturns preserves the old suffix and produces output like Doneloading 100% instead of the terminal-visible Done. This affects common progress renderers that combine \r with erase-in-line, leaving stale tails in the live and final shell output views.
Useful? React with 👍 / 👎.
Related Issue
No linked issue. This is a focused bug fix for shell output that redraws the current terminal line with carriage returns.
Problem
Captured shell output is sanitized before pi-tui renders it. The sanitizer currently removes carriage returns as ordinary control characters, so redraw sequences such as
frame1\rframe2\rframe3becomeframe1frame2frame3instead of the terminal-visible final frame,frame3.That makes progress output grow and wrap unnecessarily in the live and final shell output views.
What changed
Resolve carriage-return redraws after stripping terminal escape sequences and before removing other C0 control characters. This keeps CRLF line endings as newlines while simulating same-line overwrite behavior for progress updates.
Added regression coverage for equal-length redraws, shorter partial overwrites, and CRLF normalization.
Validation
pnpm --filter @moonshot-ai/kimi-code exec vitest run test/tui/utils/shell-output.test.tspnpm exec oxlint apps/kimi-code/src/tui/utils/shell-output.ts apps/kimi-code/test/tui/utils/shell-output.test.tspnpm --filter @moonshot-ai/kimi-code run typecheckChecklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.