Skip to content

Commit

Permalink
Implement hunk-header-style 'file' attribute
Browse files Browse the repository at this point in the history
Fixes #309
  • Loading branch information
dandavison committed Dec 19, 2020
1 parent 3c31223 commit 334dec7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/delta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::fmt::Write as FmtWrite;
use std::io::BufRead;
use std::io::Write;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 334dec7

Please sign in to comment.