Skip to main content

ConflictView

Struct ConflictView 

Source
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

Source

pub fn new(file: ConflictFile) -> Self

View a parsed file.

Source

pub fn parse(text: &str) -> Result<Self, ConflictError>

Parse text and view it.

Source

pub fn file(&self) -> &ConflictFile

The parsed file.

Source

pub fn language(self, language: impl Into<String>) -> Self

The language (a name or extension core Syntax knows).

Source

pub fn path(self, path: impl Into<String>) -> Self

The file’s path, for the language when none is set.

Source

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

Side by side, stacked, or chosen by width (default).

Source

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

Unchanged lines shown before and after each conflict (default 3).

Source

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

Show the file’s 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 base(self, show: bool) -> Self

Show the diff3 base when the markers have one (default on).

Trait Implementations§

Source§

impl Clone for ConflictView

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 ConflictView

Source§

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

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

impl Renderable for ConflictView

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

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

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§

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