cmd/stripes: page auto only when wrapped height exceeds terminal - #48
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
ceil(displayWidth / termWidth)screen rows (newwrappedRowshelper), andThe standalone "one wide line" trigger is gone. Streaming behavior and ANSI-aware width measurement are unchanged.
Behavior
Tests
TestWrappedRows— unit coverage for the arithmetic (empty line, exact-fit, boundaries, div-by-zero guard).TestPagingAutoWideContentPagesintoTestPagingAutoWideButShortNoPager(the reported case) andTestPagingAutoWideWrappingPastHeightPages(wide content that legitimately overflows via wrapping).script) with the stub pager.🤖 Generated with Claude Code