Conversation
Adds lib/ansi.ts with: - stripAnsi/visibleLength for ANSI-aware text measurement - buildPositionMap for mapping visible to ANSI positions - injectHighlight for search result highlighting - ANSI escape constants for screen control
Smart default: paginate when TTY and content exceeds terminal height. Use --no-pager to bypass. Piping always bypasses pager. less-compatible keys: j/k, space/b, g/G, /, n/N, q
- Smart default: paginate on TTY when content > terminal height - less-compatible keybindings - Search with highlighting (/ and ?) - Image re-rendering on scroll - Terminal resize handling - --no-pager flag to bypass
- Add n/N keybindings for next/prev header navigation - Move search next/prev to Ctrl+N/Ctrl+P - Add HEADING_MARKER for detecting headers in rendered output - Add isHeader field to Line type
- Remove search repeat bindings, use / again instead - Show framed image box with alt text instead of rendering - Add mouse scroll support - Fix image placeholder regex to handle ANSI codes - Skip first header on 'n' when at top of document
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.
Overview
Adds a less-style interactive pager to glowm for viewing long markdown documents. The pager activates automatically when content exceeds terminal height, with
--no-pagerflag to disable.Key Changes
Interactive pager with less-compatible keybindings
/forward,?backward with match highlighting=Line wrapping that preserves ANSI escape codes
Image handling in pager mode
Terminal resize handling
Design Decisions
The pager uses a state machine with
PagerStateholding lines, scroll position, terminal dimensions, and search state. Rendering writes directly to stdout with ANSI clear/cursor sequences rather than using a canvas abstraction.Images display as styled placeholder boxes in pager mode because terminal image rendering (Kitty protocol or ANSI blocks) doesn't integrate well with viewport scrolling. The non-pager mode still renders actual images.
Header navigation detects headers via a
HEADING_MARKERcharacter injected during markdown rendering, stripped before final output.Overall Flow
sequenceDiagram participant User participant CLI participant Pager participant Render User->>CLI: glowm file.md CLI->>CLI: Render markdown CLI->>CLI: Check content height vs terminal alt Content fits CLI->>User: Output directly else Content exceeds terminal CLI->>Pager: runPager(content, images) Pager->>Render: Initial render loop Input handling User->>Pager: Keypress/scroll Pager->>Pager: Update state Pager->>Render: Re-render viewport end User->>Pager: q Pager->>CLI: Cleanup and exit end