ratatui_toolkit/widgets/code_diff/widget/methods/stats_text.rs
1use crate::widgets::code_diff::code_diff::CodeDiff;
2
3impl CodeDiff {
4 /// Returns a formatted stats string (e.g., "+5 -3").
5 ///
6 /// # Returns
7 ///
8 /// A string showing the added and removed line counts
9 ///
10 /// # Example
11 ///
12 /// ```rust
13 /// use ratatui_toolkit::code_diff::{CodeDiff, DiffHunk, DiffLine};
14 ///
15 /// let mut diff = CodeDiff::new();
16 /// let mut hunk = DiffHunk::new(1, 1, 1, 2);
17 /// hunk.add_line(DiffLine::removed("old", 1));
18 /// hunk.add_line(DiffLine::added("new1", 1));
19 /// hunk.add_line(DiffLine::added("new2", 2));
20 /// diff.add_hunk(hunk);
21 /// assert_eq!(diff.stats_text(), "+2 -1");
22 /// ```
23 pub fn stats_text(&self) -> String {
24 format!("+{} -{}", self.added_count(), self.removed_count())
25 }
26}