Pass DisplayOptions in more places

pull/286/head
Wilfred Hughes 2022-05-13 19:41:18 +07:00
parent 3eada5b9b0
commit bfb2a5035c
4 changed files with 36 additions and 40 deletions

@ -57,10 +57,7 @@ pub fn print(
i + 1,
hunks.len(),
lang_name,
// TODO: Just pass display_options.
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);

@ -421,9 +421,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
1,
1,
&lang_name,
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
if lang_name == "Text" || summary.lhs_src == summary.rhs_src {
@ -477,9 +475,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
1,
1,
"binary",
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
if changed {
@ -499,9 +495,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
1,
1,
"binary",
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
println!("Binary contents changed.");

@ -83,9 +83,7 @@ fn display_single_column(
lang_name: &str,
src: &str,
is_lhs: bool,
use_color: bool,
in_vcs: bool,
background: BackgroundColor,
display_options: &DisplayOptions,
) -> String {
let column_width = format_line_num(src.lines().count().into()).len();
@ -96,15 +94,13 @@ fn display_single_column(
1,
1,
lang_name,
use_color,
in_vcs,
background,
display_options,
));
result.push('\n');
let mut style = Style::new();
if use_color {
style = novel_style(Style::new(), is_lhs, background);
if display_options.use_color {
style = novel_style(Style::new(), is_lhs, display_options.background_color);
}
for (i, line) in src.lines().enumerate() {
@ -342,9 +338,7 @@ pub fn print(
lang_name,
&rhs_colored_src,
false,
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
return;
@ -358,10 +352,7 @@ pub fn print(
lang_name,
&lhs_colored_src,
true,
// TODO: pass display_options directly.
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
return;
@ -400,9 +391,7 @@ pub fn print(
i + 1,
hunks.len(),
lang_name,
display_options.use_color,
display_options.in_vcs,
display_options.background_color
display_options
)
);
@ -638,6 +627,17 @@ mod tests {
#[test]
fn test_display_single_column() {
let display_options = DisplayOptions {
background_color: BackgroundColor::Dark,
use_color: false,
display_mode: DisplayMode::SideBySide,
print_unchanged: true,
tab_width: 8,
display_width: 80,
in_vcs: false,
syntax_highlight: true,
};
// Basic smoke test.
let res = display_single_column(
"foo.py",
@ -645,9 +645,7 @@ mod tests {
"Python",
"print(123)\n",
false,
true,
false,
BackgroundColor::Dark,
&display_options,
);
assert!(res.len() > 10);
}

@ -3,6 +3,7 @@
use crate::{
constants::Side,
lines::{byte_len, codepoint_len, LineNumber},
options::DisplayOptions,
positions::SingleLineSpan,
syntax::{AtomKind, MatchKind, MatchedPos, TokenKind},
};
@ -343,9 +344,7 @@ pub fn header(
hunk_num: usize,
hunk_total: usize,
language_name: &str,
use_color: bool,
in_vcs: bool,
background: BackgroundColor,
display_options: &DisplayOptions,
) -> String {
let divider = if hunk_total == 1 {
"".to_owned()
@ -353,9 +352,17 @@ pub fn header(
format!("{}/{} --- ", hunk_num, hunk_total)
};
let rhs_path_pretty = apply_header_color(rhs_display_path, use_color, background);
if hunk_num == 1 && lhs_display_path != rhs_display_path && in_vcs {
let lhs_path_pretty = apply_header_color(lhs_display_path, use_color, background);
let rhs_path_pretty = apply_header_color(
rhs_display_path,
display_options.use_color,
display_options.background_color,
);
if hunk_num == 1 && lhs_display_path != rhs_display_path && display_options.in_vcs {
let lhs_path_pretty = apply_header_color(
lhs_display_path,
display_options.use_color,
display_options.background_color,
);
let renamed = format!("Renamed {} to {}", lhs_path_pretty, rhs_path_pretty,);
format!(
"{}\n{} --- {}{}",