Skip to content

render-grid: export bounded rows after viewport - #107

Open
azooz2003-bit wants to merge 16 commits into
mainfrom
feat/mobile-render-grid-bidirectional
Open

render-grid: export bounded rows after viewport#107
azooz2003-bit wants to merge 16 commits into
mainfrom
feat/mobile-render-grid-bidirectional

Conversation

@azooz2003-bit

@azooz2003-bit azooz2003-bit commented Jul 11, 2026

Copy link
Copy Markdown

Adds an independent bounded rows-after-viewport window to the embedded render-grid export. The producer traverses one bounded range, preserves compressed pages, and leaves existing scrollback fields unchanged.

Verification:

  • zig build test -Dtest-filter="render grid" -Demit-macos-app=false
  • zig build -Demit-macos-app=false
  • universal ReleaseFast GhosttyKit build with the symbol present in all slices

Parent: manaflow-ai/cmux#7304


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Adds a bounded “rows after viewport” window to render‑grid JSON and a mode‑aware exact row scroll API for mobile. Exports now settle any pending resize first to reflect the current geometry.

  • New Features

    • Adds scrollforward_rows/scrollforward_spans after the viewport; emits primary_active_rows/primary_active_spans when the forward window stops before the active screen (capped to one viewport).
    • Cursor JSON adds location (viewport, above_viewport, below_viewport) and active_row; visible now reflects cursor mode even when off‑screen.
    • New APIs: ghostty_surface_render_grid_json_bounded(...) and ghostty_surface_mouse_scroll_with_viewport_rows(...); newer rows are excluded from the legacy entrypoint.
    • Exports are strictly bounded: caller row caps are honored, with a retained span limit and a JSON size cap to avoid oversized frames. Preserves compressed pages.
  • Migration

    • ghostty_surface_render_grid_json(...) is unchanged and excludes rows after the viewport. Use ghostty_surface_render_grid_json_bounded(surface, surface_id, len, state_seq, scrollback_lines, scrollforward_lines) to include newer rows; pass 0 to omit.
    • For precise mobile scrolling, use ghostty_surface_mouse_scroll_with_viewport_rows(surface, x, y, rows, mods); positive rows scroll upward.
    • Older JSON consumers can ignore scrollforward_*, primary_active_*, cursor.location, and cursor.active_row. Free returned strings with ghostty_string_free.

Written for commit 4f4f385. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added a new bounded terminal grid JSON export that includes both before- and after-viewport row ranges.
    • Added screen-tail VT export with caller-controlled row/byte limits.
  • Documentation
    • Clarified the rendered grid JSON frame structure, scrollback ordering, and viewport boundary semantics (including legacy “before” behavior).
  • Bug Fixes
    • Improved cursor serialization to consistently report visibility and location class (viewport/above/below).
  • Tests
    • Added coverage for bounded row traversal, iterator ordering/output-row mapping, cursor classification/visibility, and active-region bounds.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds bounded bidirectional render-grid JSON export and active-row traversal. Rendering now covers scrollback, viewport, and bounded forward rows, with region spans, row counts, cursor location metadata, and compressed-page reuse.

Changes

Terminal rendering exports

Layer / File(s) Summary
Render-grid export contract
include/ghostty.h
Documents JSON frame contents and adds the bounded export declaration with before- and after-viewport caps.
Bounded active-row traversal
src/terminal/PageList.zig
Adds bounded iteration over active rows after a historical endpoint and tests its bounds.
Bidirectional render-grid iteration
src/apprt/embedded.zig
Adds region-aware traversal across scrollback, viewport, and forward rows while reusing compressed page state.
Render-grid JSON integration
src/apprt/embedded.zig
Emits region-specific rows and spans, cursor location metadata, and wires legacy and bounded exports with validation tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CClient
  participant ghostty_surface_render_grid_json_bounded
  participant buildRenderGridJson
  participant RenderGridRowIterator
  participant RenderGridPageReader
  CClient->>ghostty_surface_render_grid_json_bounded: Provide before and after row caps
  ghostty_surface_render_grid_json_bounded->>buildRenderGridJson: Build bounded JSON frame
  buildRenderGridJson->>RenderGridRowIterator: Traverse bounded terminal regions
  RenderGridRowIterator->>RenderGridPageReader: Decode rows from page storage
  RenderGridPageReader-->>RenderGridRowIterator: Return row data
  RenderGridRowIterator-->>buildRenderGridJson: Return region and output-row mappings
  buildRenderGridJson-->>CClient: Return render-grid JSON
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: adding a bounded render-grid export for rows after the viewport.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mobile-render-grid-bidirectional

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a bounded rows-after-viewport window to render-grid exports. The main changes are:

  • A single iterator for scrollback, viewport, and scrollforward rows.
  • Temporary page reads that preserve compressed storage.
  • New scrollforward row and span fields in the JSON payload.
  • A new scrollforward cap in the public C API.

Confidence Score: 4/5

The unchanged C symbol needs an ABI-compatible extension before merging.

  • Existing five-argument binaries can resolve the symbol but leave the new scrollforward cap undefined.
  • Recompiled callers receive the updated declaration and argument order.
  • The row iterator and compressed-page ownership paths otherwise appear consistent.

include/ghostty.h and the matching exported function in src/apprt/embedded.zig

Important Files Changed

Filename Overview
include/ghostty.h Adds the scrollforward cap to the existing exported function, which breaks binary compatibility with five-argument callers.
src/apprt/embedded.zig Adds bounded bidirectional row traversal, compressed-page-preserving reads, and scrollforward JSON output.

Reviews (1): Last reviewed commit: "render-grid: export bidirectional viewpo..." | Re-trigger Greptile

Comment thread include/ghostty.h Outdated
Comment on lines 1164 to 1165
uintptr_t,
uintptr_t);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Existing Callers Read Garbage Cap

An existing binary compiled against the five-argument API can still resolve this unchanged symbol, but the new implementation reads a sixth argument that the caller never supplied. That value becomes scrollforward_lines, so mixed-version deployments can export an arbitrary number of rows after the viewport; use an ABI-compatible entry point or a new symbol for the extended signature.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/terminal/PageList.zig`:
- Around line 7979-8000: Resolve the missing PageList.activeRowsAfter reference
in the test "PageList active rows after bounded historical end": either
implement the method on PageList with the expected iterator/null behavior, or
revise the test to use the existing API that provides equivalent active-row
traversal. Ensure the test compiles and preserves its assertions for bounded
historical ends and active_bottom.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7438ba34-7408-4cf0-9824-c59a036859af

📥 Commits

Reviewing files that changed from the base of the PR and between 1db665f and 72164a1.

📒 Files selected for processing (2)
  • src/apprt/embedded.zig
  • src/terminal/PageList.zig

Comment thread src/terminal/PageList.zig
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