Skip to main content

DiffViewer

Struct DiffViewer 

Source
pub struct DiffViewer { /* private fields */ }
Expand description

Pure diff viewer that renders into a caller-owned buffer.

Implementations§

Source§

impl DiffViewer

Source

pub fn new(document: DiffDocument, options: DiffOptions) -> Self

Creates a viewer with plain initial rendering state.

Source

pub const fn document(&self) -> &DiffDocument

Returns the viewed document.

Source

pub const fn state(&self) -> &DiffState

Returns the viewer state.

Source

pub fn set_state(&mut self, state: DiffState)

Replaces the viewer state.

Source

pub fn replace_file_diffs(&mut self, files: impl IntoIterator<Item = FileDiff>)

Replaces existing file diffs in place, matching them by id.

Source

pub fn context_request(&self, change: ContextChange) -> Option<ContextRequest>

Prepares a repo refetch request for an asynchronous context update.

Source

pub fn apply_context_update( &mut self, update: ContextUpdate, area: Rect, ) -> bool

Applies a completed asynchronous context update.

Source

pub fn set_scroll(&mut self, scroll: usize)

Sets the first visible rendered row.

Source

pub fn set_focus(&mut self, focus: Option<DiffFocus>)

Sets the focused file or hunk.

Source

pub fn set_collapsed_files(&mut self, collapsed_files: BTreeSet<FileId>)

Sets the collapsed file sections.

Source

pub fn focused_file(&self) -> Option<FileId>

Returns the file containing the current focus.

Source

pub fn render(&mut self, area: Rect, buf: &mut Buffer)

Renders the current frame into buf.

Source

pub fn apply(&mut self, action: DiffAction, area: Rect) -> ViewChange

Applies an action to the viewer state.

Source

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.

Source

pub fn highlight_requests(&mut self, area: Rect) -> Vec<HighlightRequest>

Returns highlight requests for visible source rows plus configured lookahead.

Source

pub fn cancel_highlights( &mut self, requests: impl IntoIterator<Item = HighlightRequest>, )

Marks unprocessed highlight requests as requestable again.

Source

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.

Source

pub fn apply_visible_highlights<H>( &mut self, area: Rect, highlighter: &mut H, ) -> bool
where 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.

Trait Implementations§

Source§

impl Clone for DiffViewer

Source§

fn clone(&self) -> DiffViewer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DiffViewer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Widget for DiffViewer

Source§

fn size(&self, parent: Constraint) -> Size

Returns the widget size under a parent constraint.
Source§

fn render(&mut self, area: Rect, buf: &mut Buffer)

Renders the widget into an area.
Source§

fn to_buffer(&mut self, constraints: Constraint) -> Buffer

Renders this widget into a fresh buffer sized from the given constraints.
Source§

fn columns(&self, parent: Constraint) -> usize

Returns the number of columns occupied by this widget.
Source§

fn rows(&self, parent: Constraint) -> usize

Returns the number of rows occupied by this widget.
Source§

fn lines(&mut self, constraints: Constraint) -> Vec<Line>

Returns this widget rendered as styled lines, one per row. Read more
Source§

fn to_line(&mut self, constraints: Constraint) -> Line

Returns the first rendered row of this widget, or a blank line. Read more
Source§

fn display(&mut self, constraints: Constraint) -> String

Returns a plain string representation of this widget.
Source§

fn display_styled(&mut self, constraints: Constraint) -> String

Returns a string representation with terminal styling escapes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.