diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-12-19 12:36:07 +0000 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-12-19 12:48:25 +0000 |
commit | 334dec742d78d6d72715eaefaaa1c8313c6315fb (patch) | |
tree | 19261671671f088921e5396dcdedd2d8149287bc | |
parent | 3c31223dbfcbcb32c3c2da990091cc65e9f6eca1 (diff) |
Implement hunk-header-style 'file' attribute
Fixes #309
-rw-r--r-- | src/cli.rs | 3 | ||||
-rw-r--r-- | src/config.rs | 5 | ||||
-rw-r--r-- | src/delta.rs | 8 |
3 files changed, 15 insertions, 1 deletions
@@ -365,7 +365,8 @@ pub struct Opt { #[structopt(long = "hunk-header-style", default_value = "syntax")] /// Style (foreground, background, attributes) for the hunk-header. See STYLES section. The - /// style 'omit' can be used to remove the hunk header section from the output. + /// 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. 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 28e571d6..6d47ac59 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,6 +32,7 @@ pub struct Config { pub file_style: Style, pub git_config_entries: HashMap<String, GitConfigEntry>, pub hunk_header_style: Style, + pub hunk_header_style_include_file_path: bool, pub hyperlinks: bool, pub hyperlinks_file_link_format: String, pub inspect_raw_lines: cli::InspectRawLines, @@ -163,6 +164,10 @@ impl From<cli::Opt> for Config { file_style, git_config_entries: opt.git_config_entries, hunk_header_style, + hunk_header_style_include_file_path: opt + .hunk_header_style + .split(' ') + .any(|s| s == "file"), hyperlinks: opt.hyperlinks, hyperlinks_file_link_format: opt.hyperlinks_file_link_format, inspect_raw_lines: opt.computed.inspect_raw_lines, diff --git a/src/delta.rs b/src/delta.rs index de9d68e2..e401e269 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::fmt::Write as FmtWrite; use std::io::BufRead; use std::io::Write; @@ -485,6 +486,13 @@ fn handle_hunk_header_line( writeln!(painter.writer)?; } if !line.is_empty() { + if config.hunk_header_style_include_file_path { + let _ = write!( + &mut painter.output_buffer, + "{}: ", + config.file_style.paint(plus_file) + ); + }; let lines = vec![(line, State::HunkHeader)]; let syntax_style_sections = Painter::get_syntax_style_sections_for_lines( &lines, |