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. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).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.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
The vertical alignment a
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
Whether a top-level print ends this renderable’s last line. This
port’s renderables separate lines, where upstream’s end each line
with
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.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