From 2a3ed948ecc1f98dc7347ddf170ffcd384139ca1 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Thu, 19 Mar 2026 21:35:48 -0700 Subject: [PATCH] feat: preserve change markers when combining --diff with --plain When --plain is set (via CLI or config file), --diff output loses all visual markers, making it indistinguishable from plain text. The diff line filtering still works, but without Changes markers or Snip separators the output is not useful. Automatically include Changes and Snip style components when --diff is active alongside --plain. This preserves the --plain intent (no grid, no header, no line numbers) while keeping diff output readable. Closes #3630 --- CHANGELOG.md | 1 + src/bin/bat/app.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de41716..a9508f39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Features +- Preserve `--diff` change markers and snip separators when `--plain` is set, see #3630 (@mvanhorn) - Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355) - Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey) - Implement `--unbuffered` mode for streaming input, allowing partial lines to display immediately (e.g. `tail -f | bat -u`). Closes #3555, see #3583 (@mainnebula) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index dddb5559..a580ff02 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -590,7 +590,16 @@ impl App { // Plain if `--plain` is specified at least once. if self.matches.get_count("plain") > 0 { - return Some(StyleComponents(HashSet::from([StyleComponent::Plain]))); + let mut components = HashSet::from([StyleComponent::Plain]); + // When --diff is active, preserve change markers and snip separators + // so that diff output remains visually useful. + if self.matches.try_contains_id("diff").unwrap_or_default() + && self.matches.get_flag("diff") + { + components.insert(StyleComponent::Changes); + components.insert(StyleComponent::Snip); + } + return Some(StyleComponents(components)); } // Default behavior.