Skip to main content

DiffView

Struct DiffView 

Source
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

Source

pub fn new(old: &str, new: &str) -> Self

Diff two plain texts.

Source

pub fn from_diff(diff: &TextDiff) -> Self

View an existing TextDiff, keeping its context setting.

Source

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.

Source

pub fn snapshots(old: &RenderSnapshot, new: &RenderSnapshot) -> Self

Diff two render snapshots through their ANSI output, so styling regressions show as ~ lines.

Source

pub fn layout(self, layout: Layout) -> Self

Unified (default) or side by side.

Source

pub fn line_numbers(self, show: bool) -> Self

Show line numbers (default on).

Source

pub fn wrap(self, wrap: bool) -> Self

Wrap long lines (default) or truncate them with an ellipsis.

Source

pub fn context(self, lines: usize) -> Self

Unchanged lines around each change (default 3).

Source

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).

Source

pub fn emphasis(self, on: bool) -> Self

Word-level emphasis on changed lines (default on).

Source

pub fn is_equal(&self) -> bool

Whether the two sides render identically.

Source

pub fn stats(&self) -> (usize, usize, usize)

(added, removed, restyled) line counts.

Source

pub fn style_changed_lines(&self) -> Vec<usize>

The 1-based new-side lines whose text matches but styling differs.

Trait Implementations§

Source§

impl Clone for DiffView

Source§

fn clone(&self) -> Self

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 DiffView

Source§

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

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

impl Renderable for DiffView

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

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

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>

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.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more