Skip to content

feat: host chrome switch, gutter markers, reveal and select_range - #8

Merged
backnotprop merged 3 commits into
mainfrom
feat/host-api
Nov 15, 2026
Merged

backnotprop merged 3 commits into
mainfrom
feat/host-api

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Three additive engine APIs for hosts that embed diffs_rs::engine::Engine. plannotator-tui needs them for its planned git-diff review screen: the user selects lines, writes notes, and sends them to a coding agent. The host owns the header, footer, keys and a notes rail.

What each API does

  • Options.chrome (default true, which keeps today's behaviour). With false the engine draws no label row, footer or help overlay. The diff and the Files sidebar fill the whole rectangle (the minimum is 40×8 instead of 40×10), Command::Help and ? are ignored, and the loading and error placeholders name no keys. The host reads status() to show what the footer used to show.
  • Engine::set_markers(&[Marker]), where Marker { range: SourceRange, style: ratatui::style::Style }. On each visible row whose source line on that side is in the range, the first gutter cell shows ▌ in the given style. A unified row shows both line numbers, so a marker on either side applies. The cursor and selection indicators take precedence in that cell, and where markers overlap the later one wins. Each call replaces the whole set. Markers are flattened per file and side when they are set, so drawing a row costs one lookup however many markers exist. A set is rejected if any range has a stale review or an invalid range. replace() and close() drop the markers.
  • Engine::reveal(file, side, line) scrolls that source line into view and puts the cursor on it. Engine::select_range(SourceRange) makes the fixed selection a user makes with V, move, V. selection(), selected_source() and source_read() then report it. Both return an error and change nothing when the line is not displayed: the file is missing, the line is outside the file, the line is on the other side only, or the line is in a gap that has not been revealed. Revealed checked context counts as displayed.

The embedding guide (docs/embedding.md) documents all three. The example host gets --no-chrome, which makes it draw its own status row from status(). It also gets m to mark the selection or the cursor line and ' to select the last mark again.

Compatibility

All three APIs are additive. One caveat: Options is a struct with only public fields, so a host that builds it without ..Options::default() will not compile after the new field. All in-repo callers and the docs use ..Options::default(). The CHANGELOG notes this. Consider releasing it as 0.2.0. Version, tags and publishing are not touched here.

Tests

New tests in tests/engine.rs, which use only the public API through the existing test host:

  • Without chrome: the diff uses every row (header on row 0, two more code rows), help never opens, clicks map to the correct rows, the cursor stays visible past the last row and on PageDown, the 8-row minimum holds, and the error placeholder names no keys.
  • Markers: each side in split, both numbers in unified, the cursor takes precedence, lines and files outside the diff draw nothing, an empty set clears all markers, invalid and stale sets are rejected, and markers can be set before the first file arrives.
  • reveal and select_range: scrolling to a line outside the view, old and new sides, errors for gap, zero, past-end, wrong-side and missing-file lines, selection read-back and source_read bytes, gap-spanning ranges, ranges from another review, a closed engine, and checked context before and after it is revealed.

There are also unit tests for marker overlap resolution in src/engine/markers.rs.

Run locally on macOS arm64 (Git 2.50.1): cargo fmt --check, both clippy runs from CI, cargo test --release --locked --no-fail-fast -- --test-threads=1 (265 passed, 10 ignored as on main), cargo test --all-targets, the engine_host_contract host checks with the rebuilt example (6 passed), cargo +1.88.0 check --locked --all-targets and cargo doc.

…source

- Options.chrome = false draws no label row, footer or help overlay. The diff
  and sidebar fill the whole rectangle, Command::Help is ignored, and the
  placeholders name no keys. The host reads status() for the footer's state.
- Engine::set_markers takes Marker { range: SourceRange, style } values and
  draws a styled gutter glyph on visible rows whose source line on that side
  is in range. Markers are flattened per file and side when the set is
  replaced, so each drawn row costs one lookup.
- Engine::reveal(file, side, line) puts the cursor on a displayed source line,
  and Engine::select_range(range) makes the same fixed selection a user would.
  Both return an error when the line is not in the diff.
@backnotprop
backnotprop merged commit f3c5d5f into main Nov 15, 2026
5 of 6 checks passed
@backnotprop
backnotprop deleted the feat/host-api branch November 15, 2026 16:25
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