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

1//! Diff line representation.
2//!
3//! Represents a single line in a diff output, including its kind, content,
4//! and line numbers from both the old and new versions.
5//!
6//! # Structure
7//!
8//! - [`DiffLine`] - The diff line struct
9//! - [`constructors`] - Constructor functions (`new`, `context`, `added`, `removed`)
10//! - [`methods`] - Instance methods for accessing line properties
11//!
12//! # Example
13//!
14//! ```rust
15//! use ratatui_toolkit::code_diff::{DiffLine, DiffLineKind};
16//!
17//! // Create a removed line
18//! let line = DiffLine::removed("old content", 5);
19//!
20//! // Create an added line
21//! let line = DiffLine::added("new content", 5);
22//!
23//! // Create a context line (unchanged)
24//! let line = DiffLine::context("unchanged", 5, 5);
25//! ```
26
27pub mod constructors;
28pub mod methods;
29
30use crate::widgets::code_diff::enums::DiffLineKind;
31
32/// Represents a single line in a diff output.
33///
34/// A `DiffLine` contains the content of the line, its kind (context, added, removed,
35/// or hunk header), and the line numbers from both the old and new file versions.
36///
37/// # Fields
38///
39/// * `kind` - The type of diff line (context, added, removed, or hunk header)
40/// * `content` - The text content of the line
41/// * `old_line_num` - Line number in the old version (None for added lines)
42/// * `new_line_num` - Line number in the new version (None for removed lines)
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct DiffLine {
45    /// The type of this diff line.
46    pub kind: DiffLineKind,
47
48    /// The text content of the line.
49    pub content: String,
50
51    /// Line number in the old/original file.
52    /// `None` for added lines since they don't exist in the old version.
53    pub old_line_num: Option<usize>,
54
55    /// Line number in the new/modified file.
56    /// `None` for removed lines since they don't exist in the new version.
57    pub new_line_num: Option<usize>,
58}