summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-12-27 21:44:00 +0000
committerDan Davison <dandavison7@gmail.com>2020-12-27 22:06:37 +0000
commit8210334b44bd63a450cf66e4203910e4c2eb055b (patch)
treef0490c49995d00f06dfd199306d12b98d9c0e846
parent32e068bf6e736ff9d364b9d066adbfc62e69b944 (diff)
Use special style attribute to control line-number in hunk-header
-rw-r--r--src/cli.rs11
-rw-r--r--src/config.rs5
-rw-r--r--src/hunk_header.rs6
-rw-r--r--src/parse_style.rs4
-rw-r--r--src/tests/test_example_diffs.rs8
5 files changed, 23 insertions, 11 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8fa38c69..cd1555df 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -363,10 +363,13 @@ pub struct Opt {
#[structopt(long = "hyperlinks-file-link-format", default_value = "file://{path}")]
pub hyperlinks_file_link_format: String,
- #[structopt(long = "hunk-header-style", default_value = "syntax")]
- /// Style (foreground, background, attributes) for the hunk-header. See STYLES section. The
- /// special attribute 'file' can be used to include the file path in the hunk header. The style
- /// 'omit' can be used to remove the hunk header section from the output.
+ #[structopt(long = "hunk-header-style", default_value = "line-number syntax")]
+ /// Style (foreground, background, attributes) for the hunk-header. See STYLES section. Special
+ /// attributes 'file' and 'line-number' can be used to include the file path, and number of
+ /// first hunk line, in the hunk header. If included in the hunk header, 'file' and
+ /// 'line-number' are styled according to 'file-style' and 'hunk-header-decoration-style'
+ /// respectively. The style 'omit' can be used to remove the hunk header section from the
+ /// output.
pub hunk_header_style: String,
#[structopt(long = "hunk-header-decoration-style", default_value = "blue box")]
diff --git a/src/config.rs b/src/config.rs
index d7f99b20..7331a12c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -33,6 +33,7 @@ pub struct Config {
pub git_config_entries: HashMap<String, GitConfigEntry>,
pub hunk_header_style: Style,
pub hunk_header_style_include_file_path: bool,
+ pub hunk_header_style_include_line_number: bool,
pub hyperlinks: bool,
pub hyperlinks_file_link_format: String,
pub inspect_raw_lines: cli::InspectRawLines,
@@ -167,6 +168,10 @@ impl From<cli::Opt> for Config {
.hunk_header_style
.split(' ')
.any(|s| s == "file"),
+ hunk_header_style_include_line_number: opt
+ .hunk_header_style
+ .split(' ')
+ .any(|s| s == "line-number"),
hyperlinks: opt.hyperlinks,
hyperlinks_file_link_format: opt.hyperlinks_file_link_format,
inspect_raw_lines: opt.computed.inspect_raw_lines,
diff --git a/src/hunk_header.rs b/src/hunk_header.rs
index d5fbef48..2f54dd79 100644
--- a/src/hunk_header.rs
+++ b/src/hunk_header.rs
@@ -96,7 +96,11 @@ fn _write_hunk_header(
);
have_hunk_header = true;
};
- if !config.line_numbers && !config.hunk_header_style.is_raw && !config.color_only {
+ if !config.line_numbers
+ && config.hunk_header_style_include_line_number
+ && !config.hunk_header_style.is_raw
+ && !config.color_only
+ {
if have_hunk_header {
let _ = write!(&mut painter.output_buffer, ":");
}
diff --git a/src/parse_style.rs b/src/parse_style.rs
index 1fa4fb03..6b7179a9 100644
--- a/src/parse_style.rs
+++ b/src/parse_style.rs
@@ -241,8 +241,8 @@ fn parse_ansi_term_style(
style.is_strikethrough = true;
} else if word == "ul" || word == "underline" {
style.is_underline = true;
- } else if word == "file" {
- // Allow: this is meaningful in hunk-header-style.
+ } else if word == "line-number" || word == "file" {
+ // Allow: these are meaningful in hunk-header-style.
} else if !seen_foreground {
if word == "syntax" {
is_syntax_highlighted = true;
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 286ffe0c..3530b29d 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -1008,7 +1008,7 @@ src/align.rs
"--file-style",
"yellow",
"--hunk-header-style",
- "file red",
+ "file line-number red",
"--hunk-header-decoration-style",
"box",
]);
@@ -1037,7 +1037,7 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
"--file-style",
"yellow",
"--hunk-header-style",
- "file red",
+ "file line-number red",
"--hunk-header-decoration-style",
"box",
]);
@@ -1078,7 +1078,7 @@ src/delta.rs:1 │
fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() {
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
- "normal",
+ "line-number normal",
"--hunk-header-decoration-style",
"omit",
]);
@@ -1268,7 +1268,7 @@ impl<'a> Alignment<'a> {
// otherwise it will confuse assert_line_is_syntax_highlighted.
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",
- "syntax",
+ "line-number syntax",
"--hunk-header-decoration-style",
"box",
]);