pub struct DiffViewer { /* private fields */ }Expand description
Pure diff viewer that renders into a caller-owned buffer.
Implementations§
Source§impl DiffViewer
impl DiffViewer
Sourcepub fn new(document: DiffDocument, options: DiffOptions) -> Self
pub fn new(document: DiffDocument, options: DiffOptions) -> Self
Creates a viewer with plain initial rendering state.
Sourcepub fn set_decorator(&mut self, decorator: impl DiffDecorator + 'static)
pub fn set_decorator(&mut self, decorator: impl DiffDecorator + 'static)
Sets the source queried for per-file and per-hunk decorations.
Decorations are pure overlays: they change what each file header and hunk render without affecting row counts, scrolling, or focus.
Sourcepub fn clear_decorator(&mut self)
pub fn clear_decorator(&mut self)
Clears any decorator, restoring the plain diff rendering.
Sourcepub const fn document(&self) -> &DiffDocument
pub const fn document(&self) -> &DiffDocument
Returns the viewed document.
Sourcepub fn load_file_sources<E>(
&mut self,
read_blob: impl FnMut(Oid) -> Result<Vec<u8>, E>,
) -> Result<(), E>
pub fn load_file_sources<E>( &mut self, read_blob: impl FnMut(Oid) -> Result<Vec<u8>, E>, ) -> Result<(), E>
Loads full-file LOC metadata and highlight context from each text file’s blobs.
Both diff sides are read so deleted rows highlight against the old blob and added rows against the new one. Blobs are read once per object id and shared between files that reference them.
Sourcepub fn load_worktree_sources(&mut self, root: &Path)
pub fn load_worktree_sources(&mut self, root: &Path)
Loads new-side highlight context from the working tree.
Working-tree diffs have no new-side object id, so the post-image only exists on disk. Unreadable files are skipped: highlighting falls back to the hunk-only source for those.
Sourcepub const fn options(&self) -> &DiffOptions
pub const fn options(&self) -> &DiffOptions
Returns the viewer options.
Sourcepub fn replace_file_diffs(&mut self, files: impl IntoIterator<Item = FileDiff>)
pub fn replace_file_diffs(&mut self, files: impl IntoIterator<Item = FileDiff>)
Replaces existing file diffs in place, matching them by id.
Sourcepub fn replace_file_diffs_anchored(
&mut self,
files: impl IntoIterator<Item = FileDiff>,
area: Rect,
)
pub fn replace_file_diffs_anchored( &mut self, files: impl IntoIterator<Item = FileDiff>, area: Rect, )
Replaces visibility-filtered file diffs while preserving hunk focus and scroll.
Sourcepub fn is_full_file(&self) -> bool
pub fn is_full_file(&self) -> bool
Returns whether the active file is expanded to its full source.
Sourcepub fn context_request(&self, change: ContextChange) -> Option<ContextRequest>
pub fn context_request(&self, change: ContextChange) -> Option<ContextRequest>
Prepares a repo refetch request for an asynchronous context update.
Sourcepub fn apply_context_update(
&mut self,
update: ContextUpdate,
area: Rect,
) -> bool
pub fn apply_context_update( &mut self, update: ContextUpdate, area: Rect, ) -> bool
Applies a completed asynchronous context update.
Sourcepub fn set_scroll(&mut self, scroll: usize)
pub fn set_scroll(&mut self, scroll: usize)
Sets the first visible rendered row.
Sourcepub fn focused_file(&self) -> Option<FileId>
pub fn focused_file(&self) -> Option<FileId>
Returns the file containing the current focus.
Sourcepub fn apply(&mut self, action: DiffAction, area: Rect) -> ViewChange
pub fn apply(&mut self, action: DiffAction, area: Rect) -> ViewChange
Applies an action to the viewer state.
Sourcepub fn handle_input(&mut self, event: Event<()>, area: Rect) -> Control
pub fn handle_input(&mut self, event: Event<()>, area: Rect) -> Control
Applies one input event to the viewer.
Context-changing keys (., ,, x) are handled by the session loop,
which refetches diffs off the terminal thread, so they fall through here.
Sourcepub fn visible_highlight_requests(
&mut self,
area: Rect,
) -> Vec<HighlightRequest>
pub fn visible_highlight_requests( &mut self, area: Rect, ) -> Vec<HighlightRequest>
Returns highlight requests for visible source rows.
Sourcepub fn lookahead_highlight_requests(
&mut self,
area: Rect,
) -> Vec<HighlightRequest>
pub fn lookahead_highlight_requests( &mut self, area: Rect, ) -> Vec<HighlightRequest>
Returns highlight requests for one viewport after the visible rows.
Sourcepub fn highlight_requests(&mut self, area: Rect) -> Vec<HighlightRequest>
pub fn highlight_requests(&mut self, area: Rect) -> Vec<HighlightRequest>
Returns highlight requests for visible source rows plus one viewport of lookahead.
Sourcepub fn cancel_highlights(
&mut self,
requests: impl IntoIterator<Item = HighlightRequest>,
)
pub fn cancel_highlights( &mut self, requests: impl IntoIterator<Item = HighlightRequest>, )
Marks unprocessed highlight requests as requestable again.
Sourcepub fn retry_pending_highlights(&mut self)
pub fn retry_pending_highlights(&mut self)
Makes every pending highlight request eligible to be queued again.
Sourcepub fn apply_highlights(
&mut self,
results: impl IntoIterator<Item = HighlightResult>,
) -> bool
pub fn apply_highlights( &mut self, results: impl IntoIterator<Item = HighlightResult>, ) -> bool
Merges highlighted rows and returns whether a redraw is needed.
The word-diff overlay is applied here, once, so the cached Line is
ready to render with no per-frame merge work. All paths that write to the
cached highlighted rows keep this invariant: cached lines are render-ready
and already overlaid.
Sourcepub fn apply_visible_highlights<H>(
&mut self,
area: Rect,
highlighter: &mut H,
) -> boolwhere
H: DiffHighlighter + ?Sized,
pub fn apply_visible_highlights<H>(
&mut self,
area: Rect,
highlighter: &mut H,
) -> boolwhere
H: DiffHighlighter + ?Sized,
Highlights currently visible source rows through highlighter.
Event-loop owners can still use Self::highlight_requests and
Self::apply_highlights directly when highlight work runs
asynchronously.
Sourcepub fn scrollbar_style() -> ScrollbarStyle
pub fn scrollbar_style() -> ScrollbarStyle
Returns the scrollbar style used by diff views.