summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorulwlu <ooulwluoo@gmail.com>2020-12-09 00:51:52 +0900
committerGitHub <noreply@github.com>2020-12-08 15:51:52 +0000
commit8cc0c372f4d29b8ced61d92ce7c46527a7180f76 (patch)
tree3bb0d164a33a63ed221cec37bd456f6c95be5c4a
parent1dfb1f7fb18e4cc9817d11570c1d6f4ecb2e8081 (diff)
Make hunk header style to be colored with same structure while color_only #405 (#437)
* Remove force passing raw to hunk header style when color_only * Handle hunk header color when color_only * Add test for hunk header style color when color_only * Delete fixme because it actually is required * Add comment for condition that keeps structure when color_only and raw mode
-rw-r--r--src/delta.rs10
-rw-r--r--src/options/set.rs1
-rw-r--r--src/tests/test_example_diffs.rs22
3 files changed, 28 insertions, 5 deletions
diff --git a/src/delta.rs b/src/delta.rs
index d7724802..ac45ed0f 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -327,7 +327,6 @@ fn handle_generic_file_meta_header_line(
raw_line: &str,
config: &Config,
) -> std::io::Result<()> {
- // FIXME: this may be able to be refactored by moving to should_handle.
if config.file_style.is_omitted && !config.color_only {
return Ok(());
}
@@ -434,7 +433,7 @@ fn handle_hunk_header_line(
};
let (raw_code_fragment, line_numbers) = parse::parse_hunk_header(&line);
// Emit the hunk header, with any requested decoration
- if config.hunk_header_style.is_raw {
+ if config.hunk_header_style.is_raw || config.color_only {
if config.hunk_header_style.decoration_style != DecorationStyle::NoDecoration {
writeln!(painter.writer)?;
}
@@ -491,7 +490,12 @@ fn handle_hunk_header_line(
painter
.line_numbers_data
.initialize_hunk(line_numbers, plus_file.to_string());
- } else if config.line_numbers_show_first_line_number && !config.hunk_header_style.is_raw {
+ } else if config.line_numbers_show_first_line_number
+ && !config.hunk_header_style.is_raw
+ && !config.color_only
+ {
+ // With raw mode or color-only mode,
+ // we should prevent the output from creating new line for printing line number
let plus_line_number = line_numbers[line_numbers.len() - 1].0;
let formatted_plus_line_number = if config.hyperlinks {
features::hyperlinks::format_osc8_file_hyperlink(
diff --git a/src/options/set.rs b/src/options/set.rs
index eda89add..449619fd 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -198,7 +198,6 @@ pub fn set_options(
opt.file_decoration_style = "none".to_string();
opt.commit_decoration_style = "none".to_string();
opt.commit_style = "raw".to_string();
- opt.hunk_header_style = "raw".to_string();
opt.hunk_header_decoration_style = "none".to_string();
}
}
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index e9a265de..c96a83e0 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -972,7 +972,6 @@ src/align.rs
}
#[test]
- // TODO: commit-style and hunk-header-style are required to add.
fn test_file_style_with_color_only_has_style() {
let config =
integration_test_utils::make_config_from_args(&["--color-only", "--file-style", "red"]);
@@ -990,6 +989,27 @@ src/align.rs
}
#[test]
+ // TODO: commit-style is required to add.
+ fn test_hunk_header_style_with_color_only_has_style() {
+ let config = integration_test_utils::make_config_from_args(&[
+ "--color-only",
+ "--hunk-header-style",
+ "red",
+ ]);
+ let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
+
+ ansi_test_utils::assert_line_has_style(
+ &output,
+ 10,
+ "@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> {",
+ "red",
+ &config,
+ );
+ let output = strip_ansi_codes(&output);
+ assert!(output.contains("@@ -71,11 +71,8 @@ impl<'a> Alignment<'a> {"));
+ }
+
+ #[test]
fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() {
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",