ratatui_toolkit/widgets/code_diff/foundation/diff_line/constructors/context.rs
1use crate::widgets::code_diff::diff_line::DiffLine;
2use crate::widgets::code_diff::enums::DiffLineKind;
3
4impl DiffLine {
5 /// Creates a context (unchanged) diff line.
6 ///
7 /// Context lines appear in both the old and new versions of the file
8 /// and are shown without highlighting to provide surrounding context.
9 ///
10 /// # Arguments
11 ///
12 /// * `content` - The text content of the line
13 /// * `old_line_num` - Line number in the old version
14 /// * `new_line_num` - Line number in the new version
15 ///
16 /// # Returns
17 ///
18 /// A new `DiffLine` with `DiffLineKind::Context`
19 ///
20 /// # Example
21 ///
22 /// ```rust
23 /// use ratatui_toolkit::code_diff::{DiffLine, DiffLineKind};
24 ///
25 /// let line = DiffLine::context("unchanged line", 5, 7);
26 /// assert!(matches!(line.kind, DiffLineKind::Context));
27 /// ```
28 pub fn context(content: impl Into<String>, old_line_num: usize, new_line_num: usize) -> Self {
29 Self {
30 kind: DiffLineKind::Context,
31 content: content.into(),
32 old_line_num: Some(old_line_num),
33 new_line_num: Some(new_line_num),
34 }
35 }
36}