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: ColorBackground color for added lines.
added_fg: ColorForeground color for added lines.
removed_bg: ColorBackground color for removed lines.
removed_fg: ColorForeground color for removed lines.
hunk_header_bg: ColorBackground color for hunk header lines.
hunk_header_fg: ColorForeground color for hunk header lines.
line_number_fg: ColorForeground color for line numbers.
show_line_numbers: boolWhether to show line numbers.
context_lines: usizeNumber of context lines to show around changes.
style: DiffStyleThe diff display style.
gutter_width: u16Width of the gutter column (for +/- markers).
line_number_width: u16Width of line number columns.
Whether the sidebar file tree is enabled.
Default sidebar width as percentage (0-100).
Minimum sidebar width as percentage (0-100).
Maximum sidebar width as percentage (0-100).
Implementations§
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn new() -> Self
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
impl DiffConfig
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn gutter_width(self, width: u16) -> Self
pub fn gutter_width(self, width: u16) -> Self
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn hunk_header_bg(self, color: Color) -> Self
pub fn hunk_header_bg(self, color: Color) -> Self
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn hunk_header_fg(self, color: Color) -> Self
pub fn hunk_header_fg(self, color: Color) -> Self
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn line_number_fg(self, color: Color) -> Self
pub fn line_number_fg(self, color: Color) -> Self
Source§impl DiffConfig
impl DiffConfig
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn removed_bg(self, color: Color) -> Self
pub fn removed_bg(self, color: Color) -> Self
Source§impl DiffConfig
impl DiffConfig
Sourcepub fn removed_fg(self, color: Color) -> Self
pub fn removed_fg(self, color: Color) -> Self
Source§impl DiffConfig
impl DiffConfig
Source§impl DiffConfig
impl DiffConfig
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
impl DiffConfig
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
impl DiffConfig
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
impl DiffConfig
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
impl DiffConfig
Trait Implementations§
Source§impl Clone for DiffConfig
impl Clone for DiffConfig
Source§fn clone(&self) -> DiffConfig
fn clone(&self) -> DiffConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DiffConfig
impl Debug for DiffConfig
Source§impl Default for DiffConfig
impl Default for DiffConfig
Source§impl PartialEq for DiffConfig
impl PartialEq for DiffConfig
impl Eq for DiffConfig
impl StructuralPartialEq for DiffConfig
Auto Trait Implementations§
impl Freeze for DiffConfig
impl RefUnwindSafe for DiffConfig
impl Send for DiffConfig
impl Sync for DiffConfig
impl Unpin for DiffConfig
impl UnwindSafe for DiffConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().