Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new alias for 'decoration=always' #1141

Merged
merged 9 commits into from
Sep 14, 2020
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p)
- Added `-P` short flag to disable paging, revised man page description, see #1075 and #1082 (@LordFlashmeow)
- Added `--force-colorization` flag & `-f` short flag to provide an alias for forced colorization/decorization, \
revised man page description, see #1141 (@alexanderkarlis)

## Bugfixes

Expand Down
6 changes: 6 additions & 0 deletions assets/manual/bat.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Specify when to use the decorations that have been specified via '\-\-style'. Th
automatic mode only enables decorations if an interactive terminal is detected. Possible
values: *auto*, never, always.
.HP
\fB\-f\fR, \fB\-\-force\-colorization\fR
.IP
Alias for '--decorations=always --color=always'. This is useful \
if the output of bat is piped to another program, but you want \
to keep the colorization/decorations.
.HP
\fB\-\-paging\fR <when>
.IP
Specify when to use the pager. To disable the pager, use \&'\-\-paging=never' or its alias,
Expand Down
16 changes: 10 additions & 6 deletions src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ impl App {
// There's no point in wrapping when this is the case.
WrappingMode::NoWrapping
},
colored_output: match self.matches.value_of("color") {
Some("always") => true,
Some("never") => false,
Some("auto") | _ => env::var_os("NO_COLOR").is_none() && self.interactive_output,
},
colored_output: self.matches.is_present("force-colorization")
|| match self.matches.value_of("color") {
Some("always") => true,
Some("never") => false,
Some("auto") | _ => {
env::var_os("NO_COLOR").is_none() && self.interactive_output
}
},
paging_mode,
term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize),
loop_through: !(self.interactive_output
|| self.matches.value_of("color") == Some("always")
|| self.matches.value_of("decorations") == Some("always")),
|| self.matches.value_of("decorations") == Some("always")
|| self.matches.is_present("force-colorization")),
tab_width: self
.matches
.value_of("tabs")
Expand Down
12 changes: 12 additions & 0 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
an interactive terminal is detected. Possible values: *auto*, never, always.",
),
)
.arg(
Arg::with_name("force-colorization")
.long("force-colorization")
.short("f")
.conflicts_with("color")
.conflicts_with("decorations")
.overrides_with("force-colorization")
.hidden_short_help(true)
.long_help("Alias for '--decorations=always --color=always'. This is useful \
if the output of bat is piped to another program, but you want \
to keep the colorization/decorations.")
)
.arg(
Arg::with_name("paging")
.long("paging")
Expand Down