summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorryuta69 <eyma22s.yu@gmail.com>2020-10-06 11:38:53 +0900
committerGitHub <noreply@github.com>2020-10-05 22:38:53 -0400
commit1dbfd35b541fe5e4c30a2c28c85884e552630e0b (patch)
treeffad8fd12fc795cdfff932980f945332552b113d
parent31e2661cde45c573be727f6d30e0c24a0983b12f (diff)
Refactor handle_hunk_header_line and should_handle (#333)
* Delete pad and move whitespace handle into draw * Revert deleting pad * Refactor handle_hunk_header_line and should_handle
-rw-r--r--src/delta.rs20
-rw-r--r--src/tests/test_example_diffs.rs4
2 files changed, 11 insertions, 13 deletions
diff --git a/src/delta.rs b/src/delta.rs
index 0a8f1515..c0ad1ed3 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -136,11 +136,9 @@ where
painter.paint_buffered_minus_and_plus_lines();
state = State::HunkHeader;
painter.set_highlighter();
- if should_handle(&state, config) {
- painter.emit()?;
- handle_hunk_header_line(&mut painter, &line, &raw_line, &plus_file, config)?;
- continue;
- }
+ painter.emit()?;
+ handle_hunk_header_line(&mut painter, &line, &raw_line, &plus_file, config)?;
+ continue;
} else if source == Source::DiffUnified && line.starts_with("Only in ")
|| line.starts_with("Submodule ")
|| line.starts_with("Binary files ")
@@ -193,9 +191,6 @@ where
/// Should a handle_* function be called on this element?
fn should_handle(state: &State, config: &Config) -> bool {
- if *state == State::HunkHeader && config.line_numbers {
- return true;
- }
let style = config.get_style(state);
!(style.is_raw && style.decoration_style == DecorationStyle::NoDecoration)
}
@@ -381,20 +376,25 @@ fn handle_hunk_header_line(
config: &Config,
) -> std::io::Result<()> {
let decoration_ansi_term_style;
+ let mut pad = false;
let draw_fn = match config.hunk_header_style.decoration_style {
DecorationStyle::Box(style) => {
+ pad = true;
decoration_ansi_term_style = style;
draw::write_boxed
}
DecorationStyle::BoxWithUnderline(style) => {
+ pad = true;
decoration_ansi_term_style = style;
draw::write_boxed_with_underline
}
DecorationStyle::BoxWithOverline(style) => {
+ pad = true;
decoration_ansi_term_style = style;
draw::write_boxed // TODO: not implemented
}
DecorationStyle::BoxWithUnderOverline(style) => {
+ pad = true;
decoration_ansi_term_style = style;
draw::write_boxed // TODO: not implemented
}
@@ -423,8 +423,8 @@ fn handle_hunk_header_line(
}
draw_fn(
painter.writer,
- &format!("{} ", line),
- &format!("{} ", raw_line),
+ &format!("{}{}", line, if pad { " " } else { "" }),
+ &format!("{}{}", raw_line, if pad { " " } else { "" }),
&config.decorations_width,
config.hunk_header_style,
decoration_ansi_term_style,
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 9332b212..94a100bb 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -891,9 +891,7 @@ src/align.rs
} else {
output_lines[n]
};
- // TODO: this trim() can be removed by simplifing width_boxed of draw_fn.
- assert_eq!(input_line.trim(), output_line.trim());
- // assert_eq!(input_line, output_line);
+ assert_eq!(input_line, output_line);
}
}