diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-12-27 00:51:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 00:51:53 +0000 |
commit | cccfd40972c2a1e99b5efeaa4e88365d3bcd025a (patch) | |
tree | e94c09874e0795c0128b75a254f5e64cae137115 | |
parent | c5f82fe553e90d914c1df4976af1d081db66793a (diff) | |
parent | 162b98f67e6dc452a206686fee0d75d80251b7c6 (diff) |
Merge pull request #470 from dandavison/309-file-path-in-hunk-header-when-no-frag
Emit file path in hunk header when no frag
-rw-r--r-- | src/delta.rs | 47 | ||||
-rw-r--r-- | src/tests/test_example_diffs.rs | 45 |
2 files changed, 69 insertions, 23 deletions
diff --git a/src/delta.rs b/src/delta.rs index e401e269..86508a73 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -485,33 +485,36 @@ fn handle_hunk_header_line( if !config.color_only { writeln!(painter.writer)?; } - if !line.is_empty() { + if !line.is_empty() || config.hunk_header_style_include_file_path { if config.hunk_header_style_include_file_path { let _ = write!( &mut painter.output_buffer, - "{}: ", - config.file_style.paint(plus_file) + "{}{} ", + config.file_style.paint(plus_file), + if line.is_empty() { "" } else { ":" }, ); }; - let lines = vec![(line, State::HunkHeader)]; - let syntax_style_sections = Painter::get_syntax_style_sections_for_lines( - &lines, - &State::HunkHeader, - &mut painter.highlighter, - &painter.config, - ); - Painter::paint_lines( - syntax_style_sections, - vec![vec![(config.hunk_header_style, &lines[0].0)]], // TODO: compute style from state - [State::HunkHeader].iter(), - &mut painter.output_buffer, - config, - &mut None, - None, - None, - Some(false), - ); - painter.output_buffer.pop(); // trim newline + if !line.is_empty() { + let lines = vec![(line, State::HunkHeader)]; + let syntax_style_sections = Painter::get_syntax_style_sections_for_lines( + &lines, + &State::HunkHeader, + &mut painter.highlighter, + &painter.config, + ); + Painter::paint_lines( + syntax_style_sections, + vec![vec![(config.hunk_header_style, &lines[0].0)]], // TODO: compute style from state + [State::HunkHeader].iter(), + &mut painter.output_buffer, + config, + &mut None, + None, + None, + Some(false), + ); + painter.output_buffer.pop(); // trim newline + } draw_fn( painter.writer, &painter.output_buffer, diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index 72c4c5f0..94b18f11 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -1015,6 +1015,8 @@ src/align.rs "yellow", "--hunk-header-style", "file red", + "--hunk-header-decoration-style", + "box", ]); let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config); @@ -1026,7 +1028,36 @@ src/align.rs &config, ); let output = strip_ansi_codes(&output); - assert!(output.contains("src/align.rs: impl<'a> Alignment<'a> {")); + assert!(output.contains( + " +───────────────────────────────────────┐ +src/align.rs: impl<'a> Alignment<'a> { │ +───────────────────────────────────────┘ +" + )); + } + + #[test] + fn test_hunk_header_style_with_file_no_frag() { + let config = integration_test_utils::make_config_from_args(&[ + "--file-style", + "yellow", + "--hunk-header-style", + "file red", + "--hunk-header-decoration-style", + "box", + ]); + let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK_NO_FRAG, &config); + + ansi_test_utils::assert_line_has_style(&output, 5, "src/delta.rs", "yellow", &config); + let output = strip_ansi_codes(&output); + assert!(output.contains( + " +─────────────┐ +src/delta.rs │ +─────────────┘ +" + )); } #[test] @@ -1483,6 +1514,18 @@ index 8e37a9e..6ce4863 100644 parent: left, "; + const GIT_DIFF_SINGLE_HUNK_NO_FRAG: &str = "\ +diff --git a/src/delta.rs b/src/delta.rs +index e401e269..e5304e01 100644 +--- a/src/delta.rs ++++ b/src/delta.rs +@@ -1,4 +1,3 @@ +-use std::borrow::Cow; + use std::fmt::Write as FmtWrite; + use std::io::BufRead; + use std::io::Write; +"; + const GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES: &str = "\ [1;31mcommit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e[m Author: Dan Davison <dandavison7@gmail.com> |