Skip to content

fix: remove trailing space padding from TUI chat lines - #3730

Open
bakamake wants to merge 1 commit into
MoonshotAI:mainfrom
bakamake:fix/tui-copy-trailing-spaces
Open

fix: remove trailing space padding from TUI chat lines#3730
bakamake wants to merge 1 commit into
MoonshotAI:mainfrom
bakamake:fix/tui-copy-trailing-spaces

Conversation

@bakamake

Copy link
Copy Markdown

Related Issue

No linked issue — this PR addresses a direct bug report: copied lines from the TUI chat end with trailing spaces, which breaks shell backslash line continuations.

Problem

In the TUI chat, every rendered line was padded with spaces to the full terminal width. When users copied multi-line shell commands such as:

bash script.sh \
    --flag1 \
    --flag2

the copied lines ended with spaces after the \, so the shell did not treat \ as a line continuation marker.

What changed

  • Removed the fill-to-width space padding in packages/pi-tui/src/components/text.ts and packages/pi-tui/src/components/markdown.ts when no background color is applied. Left/right margins requested by the component are preserved.
  • Added regression tests in packages/pi-tui/test/tui-render.test.ts, packages/pi-tui/test/markdown.test.ts, and apps/kimi-code/test/tui/components/messages/assistant-message.test.ts to ensure code block lines (including backslash continuations) no longer have trailing spaces.
  • Generated a changeset for @moonshot-ai/kimi-code.

The main-screen and alt-screen renderers already clear each line with \x1b[2K before drawing, so the padding was not needed for display correctness.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0999f92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48fec0e00c

ℹ️ 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".

// No background - keep margins but do not pad to width. Padding
// would fill copied text with trailing spaces and break tokens
// (e.g. shell backslash line continuations).
contentLines.push(lineWithMargins);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Register the new vendored divergence

When packages/pi-tui is next synchronized from upstream, this copy-friendly rendering change can be overwritten because the package guide says every remaining local divergence must be listed and re-verified, but this new text.ts/markdown.ts behavior and its guarding tests were not added to that list. Add a divergence entry covering both components and the new tests so the fix is preserved during re-vendoring.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L3-L7

Useful? React with 👍 / 👎.

@bakamake
bakamake force-pushed the fix/tui-copy-trailing-spaces branch from 48fec0e to 0999f92 Compare September 11, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant