diff --git a/CHANGELOG.md b/CHANGELOG.md index 99385fd2..c037659b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +**visualize empty lines in diff better** + +![diff-empty-line](assets/diff-empty-line.png) + ### Breaking Changes * Do you use a custom theme? @@ -22,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * switched from textwrap to bwrap for text wrapping [[@TheBlackSheep3](https://github.com/TheBlackSheep3/)] ([#1762](https://github.com/extrawurst/gitui/issues/1762)) * more logging diagnostics when a repo cannot be opened * added to [anaconda](https://anaconda.org/conda-forge/gitui) [[@TheBlackSheep3](https://github.com/TheBlackSheep3/)] ([#1626](https://github.com/extrawurst/gitui/issues/1626)) +* visualize empty line substituted with content in diff better ([#1359](https://github.com/extrawurst/gitui/issues/1359)) ### Fixes * fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726)) diff --git a/assets/diff-empty-line.png b/assets/diff-empty-line.png new file mode 100644 index 00000000..935543d4 Binary files /dev/null and b/assets/diff-empty-line.png differ diff --git a/src/components/diff.rs b/src/components/diff.rs index d4051271..ad7fb73e 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -335,47 +335,12 @@ impl DiffComponent { } fn get_text(&self, width: u16, height: u16) -> Vec { - let mut res: Vec = Vec::new(); if let Some(diff) = &self.diff { - if diff.hunks.is_empty() { - let is_positive = diff.size_delta >= 0; - let delta_byte_size = - ByteSize::b(diff.size_delta.unsigned_abs()); - let sign = if is_positive { "+" } else { "-" }; - res.extend(vec![Line::from(vec![ - Span::raw(Cow::from("size: ")), - Span::styled( - Cow::from(format!( - "{}", - ByteSize::b(diff.sizes.0) - )), - self.theme.text(false, false), - ), - Span::raw(Cow::from(" -> ")), - Span::styled( - Cow::from(format!( - "{}", - ByteSize::b(diff.sizes.1) - )), - self.theme.text(false, false), - ), - Span::raw(Cow::from(" (")), - Span::styled( - Cow::from(format!( - "{sign}{delta_byte_size:}" - )), - self.theme.diff_line( - if is_positive { - DiffLineType::Add - } else { - DiffLineType::Delete - }, - false, - ), - ), - Span::raw(Cow::from(")")), - ])]); + return if diff.hunks.is_empty() { + self.get_text_binary(diff) } else { + let mut res: Vec = Vec::new(); + let min = self.vertical_scroll.get_top(); let max = min + height as usize; @@ -426,9 +391,44 @@ impl DiffComponent { line_cursor += hunk_len; } } - } + + res + }; } - res + + vec![] + } + + fn get_text_binary(&self, diff: &FileDiff) -> Vec { + let is_positive = diff.size_delta >= 0; + let delta_byte_size = + ByteSize::b(diff.size_delta.unsigned_abs()); + let sign = if is_positive { "+" } else { "-" }; + vec![Line::from(vec![ + Span::raw(Cow::from("size: ")), + Span::styled( + Cow::from(format!("{}", ByteSize::b(diff.sizes.0))), + self.theme.text(false, false), + ), + Span::raw(Cow::from(" -> ")), + Span::styled( + Cow::from(format!("{}", ByteSize::b(diff.sizes.1))), + self.theme.text(false, false), + ), + Span::raw(Cow::from(" (")), + Span::styled( + Cow::from(format!("{sign}{delta_byte_size:}")), + self.theme.diff_line( + if is_positive { + DiffLineType::Add + } else { + DiffLineType::Delete + }, + false, + ), + ), + Span::raw(Cow::from(")")), + ])] } fn get_line_to_add<'a>( @@ -442,6 +442,9 @@ impl DiffComponent { ) -> Line<'a> { let style = theme.diff_hunk_marker(selected_hunk); + let is_content_line = + matches!(line.line_type, DiffLineType::None); + let left_side_of_line = if end_of_hunk { Span::styled(Cow::from(symbols::line::BOTTOM_LEFT), style) } else { @@ -458,7 +461,11 @@ impl DiffComponent { }; let content = - tabs_to_spaces(line.content.as_ref().to_string()); + if !is_content_line && line.content.as_ref().is_empty() { + String::from(strings::symbol::LINE_BREAK) + } else { + tabs_to_spaces(line.content.as_ref().to_string()) + }; let content = trim_offset(&content, scrolled_right); let filled = if selected { diff --git a/src/strings.rs b/src/strings.rs index 1f856b9c..d9ca293b 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -38,6 +38,7 @@ pub mod symbol { pub const CHECKMARK: &str = "\u{2713}"; //✓ pub const SPACE: &str = "\u{02FD}"; //˽ pub const EMPTY_SPACE: &str = " "; + pub const LINE_BREAK: &str = "¶"; pub const FOLDER_ICON_COLLAPSED: &str = "\u{25b8}"; //▸ pub const FOLDER_ICON_EXPANDED: &str = "\u{25be}"; //▾ pub const EMPTY_STR: &str = "";