Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ pub struct Opt {
/// Regular expression defining navigation stop points.
pub navigate_regex: Option<String>,

#[arg(
long = "newlines",
default_value = "file diff",
value_name = "WHERE"
)]
/// Insert newlines between elements.
pub newlines: String,

#[arg(long = "no-gitconfig")]
/// Do not read any settings from git config.
///
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ pub struct Config {
pub minus_style: Style,
pub navigate_regex: Option<String>,
pub navigate: bool,
pub newline_after_diff: bool,
pub newline_after_file: bool,
pub newline_after_hunk_header: bool,
pub null_style: Style,
pub null_syntect_style: SyntectStyle,
pub pager: Option<String>,
Expand Down Expand Up @@ -410,6 +413,9 @@ impl From<cli::Opt> for Config {
minus_style: styles["minus-style"],
navigate: opt.navigate,
navigate_regex,
newline_after_diff: opt.newlines.split_whitespace().any(|s| s == "diff"),
newline_after_file: opt.newlines.split_whitespace().any(|s| s == "file"),
newline_after_hunk_header: opt.newlines.split_whitespace().any(|s| s == "hunk-header"),
null_style: Style::new(),
null_syntect_style: SyntectStyle::default(),
pager: opt.pager,
Expand Down
2 changes: 2 additions & 0 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct StateMachine<'a> {
pub handled_diff_header_header_line_file_pair: Option<(String, String)>,
pub blame_key_colors: HashMap<String, String>,
pub minus_line_counter: AmbiguousDiffMinusCounter,
pub in_hunk: bool,
}

pub fn delta<I>(lines: ByteLines<I>, writer: &mut dyn Write, config: &Config) -> std::io::Result<()>
Expand Down Expand Up @@ -140,6 +141,7 @@ impl<'a> StateMachine<'a> {
config,
blame_key_colors: HashMap::new(),
minus_line_counter: AmbiguousDiffMinusCounter::not_needed(),
in_hunk: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/handlers/commit_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl StateMachine<'_> {
if !self.test_commit_meta_header_line() {
return Ok(false);
}
self.in_hunk &= self.config.commit_style.is_omitted;
let mut handled_line = false;
self.painter.paint_buffered_minus_and_plus_lines();
self.handle_pending_line_with_diff_name()?;
Expand Down
15 changes: 11 additions & 4 deletions src/handlers/diff_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl StateMachine<'_> {
&mut self.painter,
&mut self.mode_info,
self.config,
&mut self.in_hunk,
)?;
Ok(true)
} else {
Expand Down Expand Up @@ -206,6 +207,7 @@ impl StateMachine<'_> {
&mut self.painter,
&mut self.mode_info,
self.config,
&mut self.in_hunk,
)
}

Expand Down Expand Up @@ -248,6 +250,7 @@ impl StateMachine<'_> {
&mut self.painter,
&mut self.mode_info,
self.config,
&mut self.in_hunk,
)
} else if !self.config.color_only
&& self.should_handle()
Expand All @@ -270,6 +273,7 @@ pub fn write_generic_diff_header_header_line(
painter: &mut Painter,
mode_info: &mut String,
config: &Config,
in_hunk: &mut bool
) -> std::io::Result<()> {
// If file_style is "omit", we'll skip the process and print nothing.
// However in the case of color_only mode,
Expand All @@ -279,9 +283,9 @@ pub fn write_generic_diff_header_header_line(
}
let (mut draw_fn, pad, decoration_ansi_term_style) =
draw::get_draw_function(config.file_style.decoration_style);
if !config.color_only {
// Maintain 1-1 correspondence between input and output lines.
if !config.color_only && *in_hunk && config.newline_after_diff {
writeln!(painter.writer)?;
*in_hunk = false;
}
draw_fn(
painter.writer,
Expand All @@ -292,6 +296,9 @@ pub fn write_generic_diff_header_header_line(
config.file_style,
decoration_ansi_term_style,
)?;
if !config.color_only && config.newline_after_file {
writeln!(painter.writer)?;
}
if !mode_info.is_empty() {
mode_info.truncate(0);
}
Expand Down Expand Up @@ -757,7 +764,7 @@ index 0000000..323fae0
+++ b.lua
@@ -1,5 +1,4 @@
#!/usr/bin/env lua

print("Hello")
--- World?
print("..")
Expand All @@ -766,7 +773,7 @@ index 0000000..323fae0
+++ d.lua
@@ -1,4 +1,3 @@
#!/usr/bin/env lua

print("Hello")
--- World?
"#;
Expand Down
1 change: 1 addition & 0 deletions src/handlers/hunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl StateMachine<'_> {
if let State::HunkHeader(_, parsed_hunk_header, line, raw_line) = &self.state.clone() {
self.emit_hunk_header_line(parsed_hunk_header, line, raw_line)?;
}
self.in_hunk = true;
self.state = match new_line_state(&self.line, &self.raw_line, &self.state, self.config) {
Some(HunkMinus(diff_type, raw_line)) => {
if let HunkPlus(_, _) = self.state {
Expand Down
15 changes: 11 additions & 4 deletions src/handlers/hunk_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ impl StateMachine<'_> {
if self.config.hunk_header_style.is_raw {
write_hunk_header_raw(&mut self.painter, line, raw_line, self.config)?;
} else if self.config.hunk_header_style.is_omitted {
writeln!(self.painter.writer)?;
// TODO: I don't know how to avoid the stuttering here...
if !self.config.color_only && self.in_hunk && self.config.newline_after_diff {
writeln!(self.painter.writer)?;
}
} else {
// Add a blank line below the hunk-header-line for readability, unless
// color_only mode is active.
if !self.config.color_only {
if !self.config.color_only && self.in_hunk && self.config.newline_after_diff {
writeln!(self.painter.writer)?;
}

Expand All @@ -203,6 +204,12 @@ impl StateMachine<'_> {
":",
self.config,
)?;

// Add a blank line below the hunk-header-line for readability, unless
// color_only mode is active.
if !self.config.color_only && self.config.newline_after_hunk_header {
writeln!(self.painter.writer)?;
}
};
self.painter.set_highlighter();
Ok(true)
Expand Down
1 change: 1 addition & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl StateMachine<'_> {
&mut self.painter,
&mut self.mode_info,
self.config,
&mut self.in_hunk,
)?;
handled_line = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub fn set_options(
minus_non_emph_style,
navigate,
navigate_regex,
newlines,
line_fill_method,
line_numbers,
line_numbers_left_format,
Expand Down
Loading