Repository navigation
feat: host chrome switch, gutter markers, reveal and select_range - #8
Merged
Merged
Conversation
…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.
Merged
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.
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(defaulttrue, which keeps today's behaviour). Withfalsethe 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::Helpand?are ignored, and the loading and error placeholders name no keys. The host readsstatus()to show what the footer used to show.Engine::set_markers(&[Marker]), whereMarker { 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()andclose()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 withV, move,V.selection(),selected_source()andsource_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 fromstatus(). It also getsmto mark the selection or the cursor line and'to select the last mark again.Compatibility
All three APIs are additive. One caveat:
Optionsis 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:source_readbytes, 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, theengine_host_contracthost checks with the rebuilt example (6 passed),cargo +1.88.0 check --locked --all-targetsandcargo doc.