pub struct DiffView { /* private fields */ }Expand description
A line diff as a renderable: unified (default) or side by side, with line numbers, hunk headers and word-level emphasis on changed lines.
use rich::Console;
use rich_ext::diff::DiffView;
let console = Console::builder().width(40).no_color(true).build();
let out = console.render_to_string(&DiffView::new("a\nb\n", "a\nc\n").line_numbers(false));
assert_eq!(out, "@@ -1,2 +1,2 @@\n a\n- b\n+ c");Implementations§
Source§impl DiffView
impl DiffView
Sourcepub fn from_diff(diff: &TextDiff) -> Self
pub fn from_diff(diff: &TextDiff) -> Self
View an existing TextDiff, keeping its context setting.
Sourcepub fn ansi(old: &str, new: &str) -> Self
pub fn ansi(old: &str, new: &str) -> Self
Diff two ANSI-styled texts. Lines are compared by their visible text;
lines with the same text but different styling are reported as
style-only changes (~). Each side keeps its own styling.
Sourcepub fn snapshots(old: &RenderSnapshot, new: &RenderSnapshot) -> Self
pub fn snapshots(old: &RenderSnapshot, new: &RenderSnapshot) -> Self
Diff two render snapshots through their ANSI output, so styling
regressions show as ~ lines.
Sourcepub fn line_numbers(self, show: bool) -> Self
pub fn line_numbers(self, show: bool) -> Self
Show line numbers (default on).
Sourcepub fn wrap(self, wrap: bool) -> Self
pub fn wrap(self, wrap: bool) -> Self
Wrap long lines (default) or truncate them with an ellipsis.
Sourcepub fn titles(self, old: impl Into<String>, new: impl Into<String>) -> Self
pub fn titles(self, old: impl Into<String>, new: impl Into<String>) -> Self
Titles for the old and new sides (---/+++ when unified, column
headings side by side).
Sourcepub fn style_changed_lines(&self) -> Vec<usize>
pub fn style_changed_lines(&self) -> Vec<usize>
The 1-based new-side lines whose text matches but styling differs.
Trait Implementations§
Source§impl Renderable for DiffView
impl Renderable for DiffView
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
The
(minimum, maximum) cell width this renderable wants. The default
assumes the renderable fills the available width (e.g. Panel, Table);
Text overrides it with its content width so the top-level print path can
shrink to fit. Port of __rich_measure__ / Measurement.get.Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Whether a top-level
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Auto Trait Implementations§
impl !RefUnwindSafe for DiffView
impl !UnwindSafe for DiffView
impl Freeze for DiffView
impl Send for DiffView
impl Sync for DiffView
impl Unpin for DiffView
impl UnsafeUnpin for DiffView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more