ratatui_toolkit/widgets/code_diff/foundation/diff_hunk/methods/header_text.rs
1use crate::widgets::code_diff::diff_hunk::DiffHunk;
2
3impl DiffHunk {
4 /// Returns the formatted header text for this hunk.
5 ///
6 /// Generates a unified diff style header like `@@ -1,4 +1,5 @@ context`.
7 ///
8 /// # Returns
9 ///
10 /// The formatted header string
11 ///
12 /// # Example
13 ///
14 /// ```rust
15 /// use ratatui_toolkit::code_diff::DiffHunk;
16 ///
17 /// let mut hunk = DiffHunk::new(1, 4, 1, 5);
18 /// assert_eq!(hunk.header_text(), "@@ -1,4 +1,5 @@");
19 /// ```
20 pub fn header_text(&self) -> String {
21 let base = format!(
22 "@@ -{},{} +{},{} @@",
23 self.old_start, self.old_count, self.new_start, self.new_count
24 );
25
26 if let Some(ref ctx) = self.context {
27 format!("{} {}", base, ctx)
28 } else {
29 base
30 }
31 }
32}