Skip to content

Commit bd3c49d

Browse files
author
Keith Hall
committed
Merge remote-tracking branch 'origin/master' into pacman-conf
2 parents a80d5ea + ce7a3d9 commit bd3c49d

File tree

13 files changed

+141
-20
lines changed

13 files changed

+141
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Syntax highlighting for JavaScript files that start with `#!/usr/bin/env bun` #2913 (@sharunkumar)
1010
- `bat --strip-ansi={never,always,auto}` to remove ANSI escape sequences from bat's input, see #2999 (@eth-p)
1111
- Add or remove individual style components without replacing all styles #2929 (@eth-p)
12+
- Add option `--binary=as-text` for printing binary content, see issue #2974 and PR #2976 (@einfachIrgendwer0815)
1213

1314
## Bugfixes
1415

@@ -18,6 +19,7 @@
1819
- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p)
1920
- Fix panel width when line 10000 wraps, see #2854 (@eth-p)
2021
- Fix compile issue of `time` dependency caused by standard library regression #3045 (@cyqsimon)
22+
- Fix override behavior of --plain and --paging, see issue #2731 and PR #3108 (@einfachIrgendwer0815)
2123

2224
## Other
2325

@@ -44,6 +46,7 @@
4446
- Use bat's ANSI iterator during tab expansion, see #2998 (@eth-p)
4547
- Support 'statically linked binary' for aarch64 in 'Release' page, see #2992 (@tzq0301)
4648
- Update options in shell completions and the man page of `bat`, see #2995 (@akinomyoga)
49+
- Update nix dev-dependency to v0.29.0, see #3112 (@decathorpe)
4750

4851
## Syntaxes
4952

@@ -60,6 +63,7 @@
6063
- Associate Wireguard config `/etc/wireguard/*.conf`, see #2874 (@cyqsimon)
6164
- Add support for [CFML](https://www.adobe.com/products/coldfusion-family.html), see #3031 (@brenton-at-pieces)
6265
- Map `*.mkd` files to `Markdown` syntax, see issue #3060 and PR #3061 (@einfachIrgendwer0815)
66+
- Add syntax mapping for kubernetes config files #3049 (@cyqsimon)
6367
- Add syntax mapping for `/etc/pacman.conf` #2961 (@cyqsimon)
6468

6569
## Themes

Cargo.lock

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ tempfile = "3.8.1"
9898
serde = { version = "1.0", features = ["derive"] }
9999

100100
[target.'cfg(unix)'.dev-dependencies]
101-
nix = { version = "0.26.4", default-features = false, features = ["term"] }
101+
nix = { version = "0.29", default-features = false, features = ["term"] }
102102

103103
[build-dependencies]
104104
anyhow = "1.0.86"

doc/long-help.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ Options:
2020
* unicode (␇, ␊, ␀, ..)
2121
* caret (^G, ^J, ^@, ..)
2222

23+
--binary <behavior>
24+
How to treat binary content. (default: no-printing)
25+
26+
Possible values:
27+
* no-printing: do not print any binary content
28+
* as-text: treat binary content as normal text
29+
2330
-p, --plain...
2431
Only show plain style, no decorations. This is an alias for '--style=plain'. When '-p' is
2532
used twice ('-pp'), it also disables automatic paging (alias for '--style=plain

doc/short-help.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Options:
1111
Show non-printable characters (space, tab, newline, ..).
1212
--nonprintable-notation <notation>
1313
Set notation for non-printable characters.
14+
--binary <behavior>
15+
How to treat binary content. (default: no-printing)
1416
-p, --plain...
1517
Show plain style (alias for '--style=plain').
1618
-l, --language <language>

src/bin/bat/app.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
config::{get_args_from_config_file, get_args_from_env_opts_var, get_args_from_env_vars},
1010
};
1111
use bat::style::StyleComponentList;
12+
use bat::BinaryBehavior;
1213
use bat::StripAnsiMode;
1314
use clap::ArgMatches;
1415

@@ -97,12 +98,30 @@ impl App {
9798
pub fn config(&self, inputs: &[Input]) -> Result<Config> {
9899
let style_components = self.style_components()?;
99100

101+
let extra_plain = self.matches.get_count("plain") > 1;
102+
let plain_last_index = self
103+
.matches
104+
.indices_of("plain")
105+
.and_then(Iterator::max)
106+
.unwrap_or_default();
107+
let paging_last_index = self
108+
.matches
109+
.indices_of("paging")
110+
.and_then(Iterator::max)
111+
.unwrap_or_default();
112+
100113
let paging_mode = match self.matches.get_one::<String>("paging").map(|s| s.as_str()) {
101-
Some("always") => PagingMode::Always,
114+
Some("always") => {
115+
// Disable paging if the second -p (or -pp) is specified after --paging=always
116+
if extra_plain && plain_last_index > paging_last_index {
117+
PagingMode::Never
118+
} else {
119+
PagingMode::Always
120+
}
121+
}
102122
Some("never") => PagingMode::Never,
103123
Some("auto") | None => {
104124
// If we have -pp as an option when in auto mode, the pager should be disabled.
105-
let extra_plain = self.matches.get_count("plain") > 1;
106125
if extra_plain || self.matches.get_flag("no-paging") {
107126
PagingMode::Never
108127
} else if inputs.iter().any(Input::is_stdin) {
@@ -193,6 +212,11 @@ impl App {
193212
Some("caret") => NonprintableNotation::Caret,
194213
_ => unreachable!("other values for --nonprintable-notation are not allowed"),
195214
},
215+
binary: match self.matches.get_one::<String>("binary").map(|s| s.as_str()) {
216+
Some("as-text") => BinaryBehavior::AsText,
217+
Some("no-printing") => BinaryBehavior::NoPrinting,
218+
_ => unreachable!("other values for --binary are not allowed"),
219+
},
196220
wrapping_mode: if self.interactive_output || maybe_term_width.is_some() {
197221
if !self.matches.get_flag("chop-long-lines") {
198222
match self.matches.get_one::<String>("wrap").map(|s| s.as_str()) {

src/bin/bat/clap_app.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,26 @@ pub fn build_app(interactive_output: bool) -> Command {
7777
* caret (^G, ^J, ^@, ..)",
7878
),
7979
)
80+
.arg(
81+
Arg::new("binary")
82+
.long("binary")
83+
.action(ArgAction::Set)
84+
.default_value("no-printing")
85+
.value_parser(["no-printing", "as-text"])
86+
.value_name("behavior")
87+
.hide_default_value(true)
88+
.help("How to treat binary content. (default: no-printing)")
89+
.long_help(
90+
"How to treat binary content. (default: no-printing)\n\n\
91+
Possible values:\n \
92+
* no-printing: do not print any binary content\n \
93+
* as-text: treat binary content as normal text",
94+
),
95+
)
8096
.arg(
8197
Arg::new("plain")
8298
.overrides_with("plain")
8399
.overrides_with("number")
84-
.overrides_with("paging")
85100
.short('p')
86101
.long("plain")
87102
.action(ArgAction::Count)
@@ -306,7 +321,6 @@ pub fn build_app(interactive_output: bool) -> Command {
306321
.long("paging")
307322
.overrides_with("paging")
308323
.overrides_with("no-paging")
309-
.overrides_with("plain")
310324
.value_name("when")
311325
.value_parser(["auto", "never", "always"])
312326
.default_value("auto")

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::line_range::{HighlightedLineRanges, LineRanges};
2-
use crate::nonprintable_notation::NonprintableNotation;
2+
use crate::nonprintable_notation::{BinaryBehavior, NonprintableNotation};
33
#[cfg(feature = "paging")]
44
use crate::paging::PagingMode;
55
use crate::style::StyleComponents;
@@ -44,6 +44,9 @@ pub struct Config<'a> {
4444
/// The configured notation for non-printable characters
4545
pub nonprintable_notation: NonprintableNotation,
4646

47+
/// How to treat binary content
48+
pub binary: BinaryBehavior,
49+
4750
/// The character width of the terminal
4851
pub term_width: usize,
4952

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod terminal;
5252
mod vscreen;
5353
pub(crate) mod wrapping;
5454

55-
pub use nonprintable_notation::NonprintableNotation;
55+
pub use nonprintable_notation::{BinaryBehavior, NonprintableNotation};
5656
pub use preprocessor::StripAnsiMode;
5757
pub use pretty_printer::{Input, PrettyPrinter, Syntax};
5858
pub use syntax_mapping::{MappingTarget, SyntaxMapping};

src/nonprintable_notation.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ pub enum NonprintableNotation {
1010
#[default]
1111
Unicode,
1212
}
13+
14+
/// How to treat binary content
15+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
16+
#[non_exhaustive]
17+
pub enum BinaryBehavior {
18+
/// Do not print any binary content
19+
#[default]
20+
NoPrinting,
21+
22+
/// Treat binary content as normal text
23+
AsText,
24+
}

0 commit comments

Comments
 (0)