summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2024-11-26 20:19:46 +0100
committerThomas Otto <th1000s@posteo.net>2025-08-03 17:43:25 +0200
commitd5e0565cbfa47acde98d41d8777ace5d1bc4d690 (patch)
treeaba2116476bbeba18588975497c89e5aa464a0f2 /src
parent686f19ae49e26e972ea2cc761b84ee5f99cab872 (diff)
Styled zero lines fixmain
With `interactive.diffFilter = delta --color-only` delta is called by e.g. `git add -p`, but in this mode git hides the terminal from the pager. Plus/minus lines correctly use ANSI sequences to paint up to to the end of the line, but zero lines always use spaces. This needs the terminal width, but it is not available for diffFilter. So the fallback of 80 is used, and zero styles did not extend to the full terminal width. Since zero lines are only rarely styled (e.g. via `--zero-style='syntax "#1d1f21" dim'`), this was never noticed. This also crashed delta when a zero line was longer than 80.
Diffstat (limited to 'src')
-rw-r--r--src/paint.rs2
-rw-r--r--src/tests/test_example_diffs.rs30
2 files changed, 31 insertions, 1 deletions
diff --git a/src/paint.rs b/src/paint.rs
index aaa53e5..474ea08 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -204,7 +204,7 @@ impl<'p> Painter<'p> {
self.config,
&mut self.line_numbers_data.as_mut(),
None,
- BgShouldFill::With(BgFillMethod::Spaces),
+ BgShouldFill::default(),
);
}
}
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index c91c8bd..cfc7a14 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -2137,6 +2137,36 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
"###);
}
+ #[test]
+ fn test_color_only_diff_filter_zero_style_bg() {
+ let result =
+ DeltaTest::with_args(&["--color-only", r##"--zero-style='syntax "#1d1f21" dim'"##])
+ .set_config(|c| c.available_terminal_width = 80)
+ .explain_ansi()
+ .with_input(GIT_DIFF_OF_WIDTH_81);
+
+ assert_snapshot!(result.output, @r###"
+ (normal)
+ --- a.rs
+ +++ b.rs
+ @@ -1,3 +1,3 @@
+ (normal 22)+(231) (203)if(231) (81)let(231) (149)Ok(231)(foo) { (242)// Works fine with plus hunk lines which are longer 81(normal)
+ (normal 52)-// and it works fine with minus lines, however 81(normal)
+ (dim normal 234) (242)// styled(!) zero lines can only be as long as the width fallback of 80(normal)
+ (dim normal 234) (231)panic!(); (242)/* if no tty can be queried, and delta crashes on longer lines: 81(normal)
+ "###);
+ }
+
+ const GIT_DIFF_OF_WIDTH_81: &str = r#"
+--- a.rs
++++ b.rs
+@@ -1,3 +1,3 @@
++ if let Ok(foo) { // Works fine with plus hunk lines which are longer 81
+-// and it works fine with minus lines, however 81
+ // styled(!) zero lines can only be as long as the width fallback of 80
+ panic!(); /* if no tty can be queried, and delta crashes on longer lines: 81
+"#;
+
const GIT_DIFF_SINGLE_HUNK: &str = "\
commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
Author: Dan Davison <dandavison7@gmail.com>