Skip to content

cmd/stripes: page auto only when wrapped height exceeds terminal - #48

Merged
achille-roussel merged 2 commits into
mainfrom
fix-auto-paging-of-small-documents
Jul 7, 2026
Merged

cmd/stripes: page auto only when wrapped height exceeds terminal#48
achille-roussel merged 2 commits into
mainfrom
fix-auto-paging-of-small-documents

Conversation

@achille-roussel

Copy link
Copy Markdown
Contributor

Problem

When rendering JSON/XML with --paging=auto, the pager was spawned even for tiny documents that fit on screen. The auto-pager triggered the moment any single rendered line was wider than the terminal — and JSON/XML almost always have at least one wide line (long string values, deep nesting). A 3-line document got paged just because one value was 89 cells wide on an 80-column terminal.

Fix

A wide line isn't a reason to page — the terminal wraps it. What matters is the total display rows after wrapping vs. terminal height. The auto-pager now:

  • Counts each logical line as ceil(displayWidth / termWidth) screen rows (new wrappedRows helper), and
  • Spawns the pager only once the running row total exceeds the terminal height.

The standalone "one wide line" trigger is gone. Streaming behavior and ANSI-aware width measurement are unchanged.

Behavior

Input Before After
Short doc, one wide line on 80 cols paged ❌ not paged ✓
40-key object (~42 rows) paged paged ✓
One value ~2500 cells → wraps past a 24-row screen paged (by width) paged (by wrapped height) ✓

Tests

  • TestWrappedRows — unit coverage for the arithmetic (empty line, exact-fit, boundaries, div-by-zero guard).
  • Split the old TestPagingAutoWideContentPages into TestPagingAutoWideButShortNoPager (the reported case) and TestPagingAutoWideWrappingPastHeightPages (wide content that legitimately overflows via wrapping).
  • PTY tests skip in sandboxed CI without a controlling terminal; verified all three cases by driving the built binary through a real PTY (script) with the stub pager.

🤖 Generated with Claude Code

achille-roussel and others added 2 commits July 7, 2026 14:41
The auto-pager spawned the pager the moment any single rendered line was
wider than the terminal. JSON/XML documents almost always have at least
one wide line (long string values, deep nesting), so short documents that
easily fit vertically were paged anyway.

Measure fit in wrapping-aware display rows instead: each logical line
counts for ceil(width / termWidth) screen rows, and the pager spawns only
once the running total exceeds the terminal height. Short-but-wide docs
now render straight to stdout; content that genuinely overflows — whether
by many lines or by one line wrapping past the screen — still pages.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@achille-roussel
achille-roussel merged commit 447e0c3 into main Jul 7, 2026
1 check passed
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