pub struct ConflictView { /* private fields */ }Expand description
A file’s merge conflicts as a renderable: each conflict numbered, with ours, base (when the markers have one) and theirs side by side or stacked, syntax highlighted, between a few lines of surrounding context.
Line numbers are the file’s, so they lead back to the markers. With
colour off every line keeps a marker: < ours, | base, > theirs.
Styles come from the theme’s diff.conflict.ours, diff.conflict.base
and diff.conflict.theirs (see STYLES).
use rich::Console;
use rich_ext::diff::{ConflictLayout, ConflictView};
let view = ConflictView::parse("<<<<<<< HEAD\nb\n=======\nc\n>>>>>>> topic\n")
.unwrap()
.layout(ConflictLayout::Stacked);
let console = Console::builder().width(40).no_color(true).build();
assert_eq!(
console.render_to_string(&view),
"conflict 1 of 1, lines 1-5\n ours: HEAD\n2 < b\n theirs: topic\n4 > c"
);Implementations§
Source§impl ConflictView
impl ConflictView
Sourcepub fn new(file: ConflictFile) -> Self
pub fn new(file: ConflictFile) -> Self
View a parsed file.
Sourcepub fn parse(text: &str) -> Result<Self, ConflictError>
pub fn parse(text: &str) -> Result<Self, ConflictError>
Parse text and view it.
Sourcepub fn file(&self) -> &ConflictFile
pub fn file(&self) -> &ConflictFile
The parsed file.
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 language when none is set.
Sourcepub fn layout(self, layout: ConflictLayout) -> Self
pub fn layout(self, layout: ConflictLayout) -> Self
Side by side, stacked, or chosen by width (default).
Sourcepub fn context(self, lines: usize) -> Self
pub fn context(self, lines: usize) -> Self
Unchanged lines shown before and after each conflict (default 3).
Sourcepub fn line_numbers(self, show: bool) -> Self
pub fn line_numbers(self, show: bool) -> Self
Show the file’s line numbers (default on).
Trait Implementations§
Source§impl Clone for ConflictView
impl Clone for ConflictView
Source§impl Debug for ConflictView
impl Debug for ConflictView
Source§impl Renderable for ConflictView
impl Renderable for ConflictView
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. 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
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>
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
"\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.