DiffConfig

Struct DiffConfig 

Source
pub struct DiffConfig {
Show 16 fields pub added_bg: Color, pub added_fg: Color, pub removed_bg: Color, pub removed_fg: Color, pub hunk_header_bg: Color, pub hunk_header_fg: Color, pub line_number_fg: Color, pub show_line_numbers: bool, pub context_lines: usize, pub style: DiffStyle, pub gutter_width: u16, pub line_number_width: u16, pub sidebar_enabled: bool, pub sidebar_default_width: u16, pub sidebar_min_width: u16, pub sidebar_max_width: u16,
}
Expand description

Configuration options for the CodeDiff widget.

Controls the visual appearance and behavior of the diff display, including colors for added/removed lines, line number visibility, context line count, and sidebar options.

§Fields

  • added_bg - Background color for added lines (default: dark green)
  • removed_bg - Background color for removed lines (default: dark red)
  • added_fg - Foreground color for added lines (default: green)
  • removed_fg - Foreground color for removed lines (default: red)
  • hunk_header_bg - Background color for hunk headers (default: dark gray)
  • hunk_header_fg - Foreground color for hunk headers (default: cyan)
  • line_number_fg - Foreground color for line numbers (default: dark gray)
  • show_line_numbers - Whether to display line numbers (default: true)
  • context_lines - Number of context lines to show around changes (default: 3)
  • style - The diff display style (default: SideBySide)
  • gutter_width - Width of the gutter for markers (default: 2)
  • line_number_width - Width of line number columns (default: 4)
  • sidebar_enabled - Whether the sidebar is enabled (default: false)
  • sidebar_default_width - Default sidebar width as percentage (default: 25)
  • sidebar_min_width - Minimum sidebar width as percentage (default: 10)
  • sidebar_max_width - Maximum sidebar width as percentage (default: 50)

Fields§

§added_bg: Color

Background color for added lines.

§added_fg: Color

Foreground color for added lines.

§removed_bg: Color

Background color for removed lines.

§removed_fg: Color

Foreground color for removed lines.

§hunk_header_bg: Color

Background color for hunk header lines.

§hunk_header_fg: Color

Foreground color for hunk header lines.

§line_number_fg: Color

Foreground color for line numbers.

§show_line_numbers: bool

Whether to show line numbers.

§context_lines: usize

Number of context lines to show around changes.

§style: DiffStyle

The diff display style.

§gutter_width: u16

Width of the gutter column (for +/- markers).

§line_number_width: u16

Width of line number columns.

§sidebar_enabled: bool

Whether the sidebar file tree is enabled.

§sidebar_default_width: u16

Default sidebar width as percentage (0-100).

§sidebar_min_width: u16

Minimum sidebar width as percentage (0-100).

§sidebar_max_width: u16

Maximum sidebar width as percentage (0-100).

Implementations§

Source§

impl DiffConfig

Source

pub fn new() -> Self

Creates a new diff configuration with default values.

Default colors are chosen to work well on both light and dark terminals:

  • Added lines: dark green background, bright green foreground
  • Removed lines: dark red background, bright red foreground
  • Hunk headers: gray background, cyan foreground
§Returns

A new DiffConfig with default settings

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new();
assert!(config.show_line_numbers);
Source§

impl DiffConfig

Source

pub fn added_bg(self, color: Color) -> Self

Sets the background color for added lines.

§Arguments
  • color - The background color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().added_bg(Color::Green);
Source§

impl DiffConfig

Source

pub fn added_fg(self, color: Color) -> Self

Sets the foreground color for added lines.

§Arguments
  • color - The foreground color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().added_fg(Color::LightGreen);
Source§

impl DiffConfig

Source

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

Sets the number of context lines to show around changes.

§Arguments
  • lines - Number of context lines
§Returns

Self for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().context_lines(5);
Source§

impl DiffConfig

Source

pub fn gutter_width(self, width: u16) -> Self

Sets the width of the gutter column.

The gutter displays the +/- markers for each line.

§Arguments
  • width - The gutter width in characters
§Returns

Self for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().gutter_width(3);
Source§

impl DiffConfig

Source

pub fn hunk_header_bg(self, color: Color) -> Self

Sets the background color for hunk header lines.

§Arguments
  • color - The background color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().hunk_header_bg(Color::DarkGray);
Source§

impl DiffConfig

Source

pub fn hunk_header_fg(self, color: Color) -> Self

Sets the foreground color for hunk header lines.

§Arguments
  • color - The foreground color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().hunk_header_fg(Color::Cyan);
Source§

impl DiffConfig

Source

pub fn line_number_fg(self, color: Color) -> Self

Sets the foreground color for line numbers.

§Arguments
  • color - The foreground color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().line_number_fg(Color::Gray);
Source§

impl DiffConfig

Source

pub fn line_number_width(self, width: u16) -> Self

Sets the width of line number columns.

§Arguments
  • width - The line number column width in characters
§Returns

Self for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().line_number_width(6);
Source§

impl DiffConfig

Source

pub fn removed_bg(self, color: Color) -> Self

Sets the background color for removed lines.

§Arguments
  • color - The background color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().removed_bg(Color::Red);
Source§

impl DiffConfig

Source

pub fn removed_fg(self, color: Color) -> Self

Sets the foreground color for removed lines.

§Arguments
  • color - The foreground color to use
§Returns

Self for method chaining

§Example
use ratatui::style::Color;
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().removed_fg(Color::LightRed);
Source§

impl DiffConfig

Source

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

Sets whether to display line numbers.

§Arguments
  • show - Whether to show line numbers
§Returns

Self for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().show_line_numbers(false);
Source§

impl DiffConfig

Source

pub fn sidebar_default_width(self, width: u16) -> Self

Sets the default sidebar width as a percentage (0-100).

This is the initial width when the widget is created. The width can be adjusted at runtime with resize methods.

§Arguments
  • width - The default width as percentage (clamped to min/max)
§Returns

The modified configuration for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().sidebar_default_width(30);
assert_eq!(config.sidebar_default_width, 30);
Source§

impl DiffConfig

Source

pub fn sidebar_enabled(self, enabled: bool) -> Self

Sets whether the sidebar file tree is enabled.

When enabled, the CodeDiff widget will display a file tree sidebar showing all files in a multi-file diff. The [ key toggles visibility.

§Arguments
  • enabled - Whether to enable the sidebar
§Returns

The modified configuration for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().sidebar_enabled(true);
assert!(config.sidebar_enabled);
Source§

impl DiffConfig

Source

pub fn sidebar_max_width(self, width: u16) -> Self

Sets the maximum sidebar width as a percentage (0-100).

The sidebar cannot be resized larger than this value.

§Arguments
  • width - The maximum width as percentage
§Returns

The modified configuration for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().sidebar_max_width(40);
assert_eq!(config.sidebar_max_width, 40);
Source§

impl DiffConfig

Source

pub fn sidebar_min_width(self, width: u16) -> Self

Sets the minimum sidebar width as a percentage (0-100).

The sidebar cannot be resized smaller than this value.

§Arguments
  • width - The minimum width as percentage
§Returns

The modified configuration for method chaining

§Example
use ratatui_toolkit::code_diff::DiffConfig;

let config = DiffConfig::new().sidebar_min_width(15);
assert_eq!(config.sidebar_min_width, 15);
Source§

impl DiffConfig

Source

pub fn style(self, style: DiffStyle) -> Self

Sets the diff display style.

§Arguments
  • style - The display style to use
§Returns

Self for method chaining

§Example
use ratatui_toolkit::code_diff::{DiffConfig, DiffStyle};

let config = DiffConfig::new().style(DiffStyle::Unified);

Trait Implementations§

Source§

impl Clone for DiffConfig

Source§

fn clone(&self) -> DiffConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DiffConfig

Source§

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

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

impl Default for DiffConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for DiffConfig

Source§

fn eq(&self, other: &DiffConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for DiffConfig

Source§

impl StructuralPartialEq for DiffConfig

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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