Skip to content

Shared text wrapping across the TUI - #38

Merged
jinroh merged 9 commits into
mainfrom
jinroh/textwrap
Oct 19, 2026
Merged

jinroh merged 9 commits into
mainfrom
jinroh/textwrap

Conversation

@jinroh

@jinroh jinroh commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds internal/tui/textwrap and uses it for wrapped TUI content, including expanded commands, diffs, and prose. Wrapping styled segments keeps their styles attached and preserves text and indentation across rows.

The main goal is to be able to properly wrap code / tool outputs when expanded to be able to review the full content.
For example, this source line:

    result, err := client.Execute(ctx, command, request, opts.WithTimeout(timeout), opts.WithRegion(region))

was truncated when expanded

  42 +     result, err := client.Execute(ctx, command, request, opts.WithTimeou…

and now renders in an 80-column diff as:

  42 +     result, err := client.Execute(ctx, command, request,
     +     opts.WithTimeout(timeout), opts.WithRegion(region))

Strings and comments stay together when they fit on a row. The wrapper also supports caller-specific breakpoints, prefixes, repeated indentation, trailing spaces, and ellipses.

Migrates chat, approval, permissions, welcome, status, questionnaire, and login text to the new package, and removes the old wrapping ad-hoc code.

How to test it

Run BITS_FAKE_BACKEND=1 go run .

load("fakedata/exec_wrap.star", "all"); all()

Also added fuzz testing for wrapping and diffrender tests for gutter alignment, string literals, and trailing whitespace.

Checklist

  • I have reviewed the contributing guidelines (CONTRIBUTING.md in the repository root).
  • I have added tests or explained why they are not needed.
  • I have updated the documentation if needed.

The expanded view word-wraps every command line instead of truncating it, keeping syntax colors across rows. The first line hangs under the command's first column; later lines wrap behind the │ branch. Adds fakedata/exec_wrap.star for manual QA.
…ands

Leading indentation is repeated on every wrapped row, the first row wraps to its own width, and rows the word wrapper leaves too wide are hard-wrapped instead of truncated. Drop & from the shell breakpoints. Adds indentation() and operators() to fakedata/exec_wrap.star.
Wrap styled segments to a cell width with prefixes, breakpoints, kept
indentation and optional ellipsis. Exec invocations and inspection rows
now use it instead of ad-hoc ANSI wrappers.
diffrender.Highlight returns styled segments instead of ANSI strings,
and Options.Wrap wraps long diff lines under the gutter. Expanded file
changes use it; compact rendering is byte-identical.
@jinroh
jinroh requested a review from a team as a code owner October 16, 2026 23:19
@jinroh jinroh changed the title Jinroh/textwrap Shared text wrapping across the TUI Oct 16, 2026

@datadog-official datadog-official 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.

Bits Code Review: FAIL

Expanded diffs can split a short string literal after an overlong identifier and discard its internal space. The verified one-line suggestion preserves the literal and passes the relevant existing tests.

Open Bits AI session

🤖 Bits Code Review · Commit d083f71

Comment thread internal/tui/textwrap/textwrap.go Outdated
Keeping whitespace by default when wrapping, so text shown as written
(diffs, exec commands and output, the approval prompt) no longer loses
spaces at soft breaks. Prose opts out with the new TrimSpace option
which replaces KeepTrailingSpace.
@jinroh
jinroh merged commit 9409397 into main Oct 19, 2026
14 checks passed
@jinroh
jinroh deleted the jinroh/textwrap branch October 19, 2026 10:21
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.

2 participants