pub struct SourceDiff { /* private fields */ }Expand description
A syntax-highlighted diff of two versions of a source file.
Each side is highlighted whole, then split into lines; word-level
emphasis goes on top. The language comes from language
or the extension of path.
use rich::Console;
use rich_ext::diff::SourceDiff;
let diff = SourceDiff::new("fn a() {}\n", "fn b() {}\n").path("src/lib.rs");
let console = Console::builder().width(40).no_color(true).build();
assert!(console.render_to_string(&diff).contains("+ fn b() {}"));Implementations§
Source§impl SourceDiff
impl SourceDiff
Sourcepub fn new(old: impl Into<String>, new: impl Into<String>) -> Self
pub fn new(old: impl Into<String>, new: impl Into<String>) -> Self
Diff two versions of a source text.
Sourcepub fn language(self, language: impl Into<String>) -> Self
pub fn language(self, language: impl Into<String>) -> Self
The language (a name or extension core Syntax knows).
Sourcepub fn path(self, path: impl Into<String>) -> Self
pub fn path(self, path: impl Into<String>) -> Self
The file’s path, for the title, links and (without
language) the language.
Sourcepub fn paths(self, old: impl Into<String>, new: impl Into<String>) -> Self
pub fn paths(self, old: impl Into<String>, new: impl Into<String>) -> Self
Different old and new paths (a rename).
Sourcepub fn line_numbers(self, show: bool) -> Self
pub fn line_numbers(self, show: bool) -> Self
Show line numbers (default on).
Sourcepub fn titles(self, show: bool) -> Self
pub fn titles(self, show: bool) -> Self
Show the paths as titles (default on, when a path is set).
Sourcepub fn link_template(self, template: impl Into<String>) -> Self
pub fn link_template(self, template: impl Into<String>) -> Self
Link line numbers through an editor or web URL template with {path}
and {line} (and {column}, always 1), such as
vscode://file/{path}:{line}.
Sourcepub fn hyperlinker(self, linker: Hyperlinker) -> Self
pub fn hyperlinker(self, linker: Hyperlinker) -> Self
Link line numbers through a Hyperlinker (file:// URLs by
default, relative paths resolved against its base directory).
Trait Implementations§
Source§impl Clone for SourceDiff
impl Clone for SourceDiff
Source§impl Debug for SourceDiff
impl Debug for SourceDiff
Source§impl Renderable for SourceDiff
impl Renderable for SourceDiff
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
(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
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.