Skip to content

Wrap logs correctly at terminal width#361

Draft
jw2 wants to merge 1 commit into
mainfrom
jw2/log-full-terminal-width
Draft

Wrap logs correctly at terminal width#361
jw2 wants to merge 1 commit into
mainfrom
jw2/log-full-terminal-width

Conversation

@jw2

@jw2 jw2 commented Jul 2, 2026

Copy link
Copy Markdown

Why

In lstk logs --follow, log lines wrapped narrower than the terminal. HardWrap counts characters, but styled prefixes (e.g. styles.Secondary.Render("container | ")) embed invisible ANSI escape sequences. Those bytes were counted as visible width, so wrapping fired before the visible content reached the terminal edge.

What changes

  • ANSI-aware log wrapping. renderLogLine now takes an availableWidth and a continuationIndent. It wraps the message on visible width, indents continuation lines to align under the message (past the prefix), and preserves the meta/message styling split (" : " boundary) across wrap points.
  • app.go LogLineEvent handler measures the visible prefix width via lipgloss.Width and passes the remaining width to renderLogLine. Pre-wrapped lines are flagged (styledLine.preWrapped) so View() emits them verbatim instead of re-wrapping.
  • Tests: unit coverage in logrender_test.go for plain wrap, visible-prefix width, meta/message styling across wraps, continuation indent, and zero-width passthrough; a golden-file test (TestAppLogLineEventWrapsAtTerminalWidth) for the end-to-end event path.

Note on the test changes

withTrueColorProfile mutates lipgloss's package-global color profile. The tests using it were marked t.Parallel(), which is a race: a sibling's cleanup restoring the default profile mid-run strips the colors another test is asserting on, producing intermittent failures. Those tests are now serial, matching the convention already used by the inline profile-mutating tests in app_test.go.

Testing

  • make test — all green (internal/ui verified stable across 20 consecutive runs).

🤖 Generated with Claude Code

@jw2 jw2 added semver: minor docs: skip Pull request does not require documentation changes labels Jul 2, 2026
@jw2 jw2 self-assigned this Jul 2, 2026
@jw2 jw2 force-pushed the jw2/log-full-terminal-width branch from c53da31 to afc1c4f Compare July 2, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant