ratatui_toolkit/widgets/code_diff/foundation/diff_line/constructors/added.rs
1use crate::widgets::code_diff::diff_line::DiffLine;
2use crate::widgets::code_diff::enums::DiffLineKind;
3
4impl DiffLine {
5 /// Creates an added diff line.
6 ///
7 /// Added lines exist only in the new version of the file and are typically
8 /// displayed with a green background and a '+' prefix.
9 ///
10 /// # Arguments
11 ///
12 /// * `content` - The text content of the line
13 /// * `new_line_num` - Line number in the new version
14 ///
15 /// # Returns
16 ///
17 /// A new `DiffLine` with `DiffLineKind::Added`
18 ///
19 /// # Example
20 ///
21 /// ```rust
22 /// use ratatui_toolkit::code_diff::{DiffLine, DiffLineKind};
23 ///
24 /// let line = DiffLine::added("new line", 10);
25 /// assert!(matches!(line.kind, DiffLineKind::Added));
26 /// assert!(line.old_line_num.is_none());
27 /// ```
28 pub fn added(content: impl Into<String>, new_line_num: usize) -> Self {
29 Self {
30 kind: DiffLineKind::Added,
31 content: content.into(),
32 old_line_num: None,
33 new_line_num: Some(new_line_num),
34 }
35 }
36}