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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion doc/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <language>
Explicitly set the language for syntax highlighting. The language can be specified as a
Expand Down
33 changes: 25 additions & 8 deletions src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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::<String>("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
Expand Down Expand Up @@ -422,13 +438,14 @@ impl App {
}
}
},
colored_output: self.matches.get_flag("force-colorization")
|| match self.matches.get_one::<String>("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::<String>("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
Expand Down
4 changes: 3 additions & 1 deletion src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading