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
5 changes: 5 additions & 0 deletions src/ansi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ mod tests {
assert_eq!(measure_text_width("a\nb\n"), 2);
}

#[test]
fn test_measure_text_width_ignores_bom() {
assert_eq!(measure_text_width("a\u{feff}b"), 2);
}

#[test]
fn test_strip_ansi_codes_osc_hyperlink() {
assert_eq!(strip_ansi_codes("\x1b[38;5;4m\x1b]8;;file:///Users/dan/src/delta/src/ansi/mod.rs\x1b\\src/ansi/mod.rs\x1b]8;;\x1b\\\x1b[0m\n"),
Expand Down
2 changes: 1 addition & 1 deletion src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a> StateMachine<'a> {
}

fn ingest_line_utf8(&mut self, raw_line: String) {
self.raw_line = raw_line;
self.raw_line = raw_line.replace('\u{feff}', "");
// When a file has \r\n line endings, git sometimes adds ANSI escape sequences between the
// \r and \n, in which case byte_lines does not remove the \r. Remove it now. [EndCRLF]
// TODO: Limit the number of characters we examine when looking for the \r?
Expand Down
40 changes: 37 additions & 3 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ fn gather_features(
if opt.hyperlinks {
gather_builtin_features_recursively("hyperlinks", &mut features, builtin_features, opt);
}
if opt.line_numbers {
gather_builtin_features_recursively("line-numbers", &mut features, builtin_features, opt);
}
if opt.navigate {
gather_builtin_features_recursively("navigate", &mut features, builtin_features, opt);
}
Expand Down Expand Up @@ -423,6 +420,12 @@ fn gather_features(
);
}

// Gather `line-numbers` after theme features so theme-provided line-number styles are not
// overridden by the built-in default styles when `--line-numbers` is enabled.
if opt.line_numbers {
gather_builtin_features_recursively("line-numbers", &mut features, builtin_features, opt);
}

Vec::<String>::from(features)
}

Expand Down Expand Up @@ -828,6 +831,37 @@ pub mod tests {
remove_file(git_config_path).unwrap();
}

#[test]
fn test_line_numbers_flag_does_not_override_theme_line_number_styles() {
let git_config_contents = b"
[delta]
features = catppuccin-latte

[delta \"catppuccin-latte\"]
line-numbers-left-style = red
line-numbers-minus-style = yellow
line-numbers-zero-style = green
line-numbers-plus-style = blue
line-numbers-right-style = magenta
";
let git_config_path =
"delta__test_line_numbers_flag_does_not_override_theme_line_number_styles.gitconfig";

let opt = integration_test_utils::make_options_from_args_and_git_config(
&["--line-numbers"],
Some(git_config_contents),
Some(git_config_path),
);

assert_eq!(opt.line_numbers_left_style, "red");
assert_eq!(opt.line_numbers_minus_style, "yellow");
assert_eq!(opt.line_numbers_zero_style, "green");
assert_eq!(opt.line_numbers_plus_style, "blue");
assert_eq!(opt.line_numbers_right_style, "magenta");

remove_file(git_config_path).unwrap();
}

#[test]
fn test_parse_width_specifier() {
use super::parse_width_specifier;
Expand Down
16 changes: 16 additions & 0 deletions src/tests/integration_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,20 @@ ignored! 2
(green)+2(normal)",
);
}

#[test]
fn test_delta_test_ignores_bom_in_raw_output_with_line_numbers() {
let input = "@@ -1,1 +1,1 @@ fn foo() {\n-\u{feff}abc\n+\u{feff}abd\n";
DeltaTest::with_args(&["--raw"])
.set_config(|c| c.pager = None)
.set_config(|c| c.line_numbers = true)
.with_input(input)
.expect(
r#"
#indent_mark
@@ -1,1 +1,1 @@ fn foo() {
1 ⋮ │-abc
⋮ 1 │+abd"#,
);
}
}