ratatui_toolkit/widgets/code_diff/foundation/diff_config/
mod.rs

1//! Configuration for the diff widget.
2//!
3//! Contains styling and display options for the code diff widget.
4//!
5//! # Structure
6//!
7//! - [`DiffConfig`] - The configuration struct
8//! - [`constructors`] - Constructor functions (`new`, `default`)
9//! - [`methods`] - Builder methods for configuration
10//!
11//! # Example
12//!
13//! ```rust
14//! use ratatui::style::Color;
15//! use ratatui_toolkit::code_diff::DiffConfig;
16//!
17//! let config = DiffConfig::new()
18//!     .added_bg(Color::Green)
19//!     .removed_bg(Color::Red)
20//!     .show_line_numbers(true);
21//! ```
22
23pub mod constructors;
24pub mod methods;
25
26use ratatui::style::Color;
27
28use crate::widgets::code_diff::enums::DiffStyle;
29
30/// Configuration options for the CodeDiff widget.
31///
32/// Controls the visual appearance and behavior of the diff display,
33/// including colors for added/removed lines, line number visibility,
34/// context line count, and sidebar options.
35///
36/// # Fields
37///
38/// * `added_bg` - Background color for added lines (default: dark green)
39/// * `removed_bg` - Background color for removed lines (default: dark red)
40/// * `added_fg` - Foreground color for added lines (default: green)
41/// * `removed_fg` - Foreground color for removed lines (default: red)
42/// * `hunk_header_bg` - Background color for hunk headers (default: dark gray)
43/// * `hunk_header_fg` - Foreground color for hunk headers (default: cyan)
44/// * `line_number_fg` - Foreground color for line numbers (default: dark gray)
45/// * `show_line_numbers` - Whether to display line numbers (default: true)
46/// * `context_lines` - Number of context lines to show around changes (default: 3)
47/// * `style` - The diff display style (default: SideBySide)
48/// * `gutter_width` - Width of the gutter for markers (default: 2)
49/// * `line_number_width` - Width of line number columns (default: 4)
50/// * `sidebar_enabled` - Whether the sidebar is enabled (default: false)
51/// * `sidebar_default_width` - Default sidebar width as percentage (default: 25)
52/// * `sidebar_min_width` - Minimum sidebar width as percentage (default: 10)
53/// * `sidebar_max_width` - Maximum sidebar width as percentage (default: 50)
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct DiffConfig {
56    /// Background color for added lines.
57    pub added_bg: Color,
58
59    /// Foreground color for added lines.
60    pub added_fg: Color,
61
62    /// Background color for removed lines.
63    pub removed_bg: Color,
64
65    /// Foreground color for removed lines.
66    pub removed_fg: Color,
67
68    /// Background color for hunk header lines.
69    pub hunk_header_bg: Color,
70
71    /// Foreground color for hunk header lines.
72    pub hunk_header_fg: Color,
73
74    /// Foreground color for line numbers.
75    pub line_number_fg: Color,
76
77    /// Whether to show line numbers.
78    pub show_line_numbers: bool,
79
80    /// Number of context lines to show around changes.
81    pub context_lines: usize,
82
83    /// The diff display style.
84    pub style: DiffStyle,
85
86    /// Width of the gutter column (for +/- markers).
87    pub gutter_width: u16,
88
89    /// Width of line number columns.
90    pub line_number_width: u16,
91
92    /// Whether the sidebar file tree is enabled.
93    pub sidebar_enabled: bool,
94
95    /// Default sidebar width as percentage (0-100).
96    pub sidebar_default_width: u16,
97
98    /// Minimum sidebar width as percentage (0-100).
99    pub sidebar_min_width: u16,
100
101    /// Maximum sidebar width as percentage (0-100).
102    pub sidebar_max_width: u16,
103}