1
0
mirror of https://github.com/sharkdp/bat.git synced 2026-02-08 00:32:08 +00:00

Limit overstrike stripping to man pages and help

This commit is contained in:
Alex Kirk
2025-12-11 05:45:44 +01:00
parent 59c5896902
commit de414ed631
2 changed files with 27 additions and 9 deletions

View File

@@ -270,14 +270,18 @@ impl<'a> InteractivePrinter<'a> {
|| matches!(config.binary, BinaryBehavior::AsText))
&& (config.colored_output || config.strip_ansi == StripAnsiMode::Auto);
let (is_plain_text, highlighter_from_set) = if needs_to_match_syntax {
let (is_plain_text, highlighter_from_set, syntax_name) = if needs_to_match_syntax {
// Determine the type of syntax for highlighting
const PLAIN_TEXT_SYNTAX: &str = "Plain Text";
match assets.get_syntax(config.language, input, &config.syntax_mapping) {
Ok(syntax_in_set) => (
syntax_in_set.syntax.name == PLAIN_TEXT_SYNTAX,
Some(HighlighterFromSet::new(syntax_in_set, theme)),
),
Ok(syntax_in_set) => {
let syntax_name = syntax_in_set.syntax.name.as_str();
(
syntax_name == PLAIN_TEXT_SYNTAX,
Some(HighlighterFromSet::new(syntax_in_set, theme)),
syntax_name,
)
}
Err(Error::UndetectedSyntax(_)) => (
true,
@@ -287,12 +291,13 @@ impl<'a> InteractivePrinter<'a> {
.map(|s| HighlighterFromSet::new(s, theme))
.expect("A plain text syntax is available"),
),
PLAIN_TEXT_SYNTAX,
),
Err(e) => return Err(e),
}
} else {
(false, None)
(false, None, "")
};
// Determine when to strip ANSI sequences
@@ -304,8 +309,8 @@ impl<'a> InteractivePrinter<'a> {
_ => false,
};
// Strip overstrike only when we have syntax highlighting (not plain text).
let strip_overstrike = !is_plain_text;
// Strip overstrike for man pages and help messages.
let strip_overstrike = matches!(syntax_name, "Manpage" | "Command Help");
Ok(InteractivePrinter {
panel_width,

View File

@@ -2556,7 +2556,7 @@ fn no_strip_overstrike_for_plain_text() {
#[test]
fn strip_overstrike_with_syntax_highlighting() {
// Overstrike is stripped when syntax highlighting is applied (e.g., for help)
// Overstrike is stripped for certain syntax highlighting like command help.
bat()
.arg("--force-colorization")
.arg("--language=help")
@@ -2581,6 +2581,19 @@ fn strip_overstrike_for_manpage_syntax() {
.stderr("");
}
#[test]
fn no_strip_overstrike_for_other_syntax() {
// Overstrike is NOT stripped for other syntaxes (e.g., Rust)
bat()
.arg("--force-colorization")
.arg("--language=rust")
.arg("overstrike.txt")
.assert()
.success()
.stdout(predicate::str::contains("\x08"))
.stderr("");
}
#[test]
fn show_all_shows_backspace_with_caret_notation() {
// --show-all should display backspace characters (not strip them)