diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5bcb2ccb..6291349782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Add `--fallback-syntax`/`--fallback-language` to apply syntax highlighting only when auto-detection fails, see #1341 (@Xavrir) - Map `BUILD` case sensitively to Python (Starlark) for Bazel, see #3576 (@vorburger) - Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres) +- Make -ppp disable syntax highlighting #4020 (@quixaq) ## Bugfixes - Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa) diff --git a/doc/long-help.txt b/doc/long-help.txt index b4b0710783..2a7868d157 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -30,7 +30,8 @@ Options: -p, --plain... Only show plain style, no decorations. This is an alias for '--style=plain'. When '-p' is used twice ('-pp'), it also disables automatic paging (alias for '--style=plain - --paging=never'). + --paging=never'). When '-p' is used three times ('-ppp'), it also disables syntax + highlighting (alias for '--style=plain --paging=never --color=never'). -l, --language Explicitly set the language for syntax highlighting. The language can be specified as a diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index feb2e11e95..992cbc14c8 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -270,6 +270,12 @@ impl App { let style_components = self.style_components()?; let extra_plain = self.matches.get_count("plain") > 1; + let extra_extra_plain = self.matches.get_count("plain") > 2; + let plain_second_index = self + .matches + .indices_of("plain") + .and_then(|mut iter| iter.nth(0)) + .unwrap_or_default(); let plain_last_index = self .matches .indices_of("plain") @@ -280,11 +286,21 @@ impl App { .indices_of("paging") .and_then(Iterator::max) .unwrap_or_default(); + let color_last_index = self + .matches + .indices_of("color") + .and_then(Iterator::max) + .unwrap_or_default(); + let force_color_last_index = self + .matches + .indices_of("force-colorization") + .and_then(Iterator::max) + .unwrap_or_default(); let paging_mode = match self.matches.get_one::("paging").map(|s| s.as_str()) { Some("always") => { // Disable paging if the second -p (or -pp) is specified after --paging=always - if extra_plain && plain_last_index > paging_last_index { + if extra_plain && plain_second_index > paging_last_index { PagingMode::Never } else { PagingMode::Always @@ -422,13 +438,14 @@ impl App { } } }, - colored_output: self.matches.get_flag("force-colorization") - || match self.matches.get_one::("color").map(|s| s.as_str()) { - Some("always") => true, - Some("never") => false, - Some("auto") => !env_no_color() && self.interactive_output, - _ => unreachable!("other values for --color are not allowed"), - }, + colored_output: self.matches.get_flag("force-colorization") && { + force_color_last_index > plain_last_index || !extra_extra_plain + } || match self.matches.get_one::("color").map(|s| s.as_str()) { + Some("always") => color_last_index > plain_last_index || !extra_extra_plain, + Some("never") => false, + Some("auto") => !env_no_color() && self.interactive_output && !extra_extra_plain, + _ => unreachable!("other values for --color are not allowed"), + }, paging_mode, term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), loop_through: !(self.interactive_output diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 9d57fc92f1..3d4d76e378 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -106,7 +106,9 @@ pub fn build_app(interactive_output: bool) -> Command { .long_help( "Only show plain style, no decorations. This is an alias for \ '--style=plain'. When '-p' is used twice ('-pp'), it also disables \ - automatic paging (alias for '--style=plain --paging=never').", + automatic paging (alias for '--style=plain --paging=never'). \ + When '-p' is used three times ('-ppp'), it also disables \ + syntax highlighting (alias for '--style=plain --paging=never --color=never').", ), ) .arg(