mirror of
https://github.com/sharkdp/bat
synced 2025-02-17 05:18:28 +00:00
Add a --style=default option (#2119)
* Add a --style=default option * Added --style=default test and CHANGELOG entry * Format CHANGELOG.md options with quotes Co-authored-by: Martin Nordholts <enselic@gmail.com> * Update help text for '--style' * Make --style=default the default option * Update style descriptions: "basic" -> "recommended" * Add integration test for --style=default as default * Update clap long help for --style
This commit is contained in:
parent
a6bd28a78b
commit
adea895026
9 changed files with 69 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
## Features
|
||||
|
||||
- Correctly render tab stops in --show-all, see #2038 (@Synthetica9)
|
||||
- Add a `--style=default` option, less verbose than `full`, see #2061 (@IsaacHorvath)
|
||||
- Enable BusyBox less as pager, see #2162 (@nfisher1226)
|
||||
|
||||
## Bugfixes
|
||||
|
|
2
assets/completions/_bat.ps1.in
vendored
2
assets/completions/_bat.ps1.in
vendored
|
@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
|
|||
[CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
|
||||
[CompletionResult]::new('--map-syntax', 'map-syntax', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
|
||||
[CompletionResult]::new('--theme', 'theme', [CompletionResultType]::ParameterName, 'Set the color theme for syntax highlighting.')
|
||||
[CompletionResult]::new('--style', 'style', [CompletionResultType]::ParameterName, 'Comma-separated list of style elements to display (*auto*, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).')
|
||||
[CompletionResult]::new('--style', 'style', [CompletionResultType]::ParameterName, 'Comma-separated list of style elements to display (*default*, auto, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).')
|
||||
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
|
||||
[CompletionResult]::new('--line-range', 'line-range', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
|
||||
[CompletionResult]::new('-A', 'A', [CompletionResultType]::ParameterName, 'Show non-printable characters (space, tab, newline, ..).')
|
||||
|
|
2
assets/completions/bat.fish.in
vendored
2
assets/completions/bat.fish.in
vendored
|
@ -56,7 +56,7 @@ complete -c {{PROJECT_EXECUTABLE}} -s P -d "Disable paging. Alias for '--paging=
|
|||
|
||||
complete -c {{PROJECT_EXECUTABLE}} -s A -l show-all -d "Show non-printable characters like space/tab/newline" -n "not __fish_seen_subcommand_from cache"
|
||||
|
||||
complete -c {{PROJECT_EXECUTABLE}} -l style -xka "auto full plain changes header header-filename header-filesize grid rule numbers snip" -d "Comma-separated list of style elements or presets to display with file contents" -n "not __fish_seen_subcommand_from cache"
|
||||
complete -c {{PROJECT_EXECUTABLE}} -l style -xka "default auto full plain changes header header-filename header-filesize grid rule numbers snip" -d "Comma-separated list of style elements or presets to display with file contents" -n "not __fish_seen_subcommand_from cache"
|
||||
|
||||
complete -c {{PROJECT_EXECUTABLE}} -l tabs -x -d "<T> Set the tab width to T spaces (width of 0 passes tabs through directly)" -n "not __fish_seen_subcommand_from cache"
|
||||
|
||||
|
|
2
assets/completions/bat.zsh.in
vendored
2
assets/completions/bat.zsh.in
vendored
|
@ -75,7 +75,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
|
|||
;;
|
||||
|
||||
style)
|
||||
_values -s , 'style' auto full plain changes header header-filename header-filesize grid rule numbers snip
|
||||
_values -s , 'style' default auto full plain changes header header-filename header-filesize grid rule numbers snip
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
|
2
assets/manual/bat.1.in
vendored
2
assets/manual/bat.1.in
vendored
|
@ -146,7 +146,7 @@ Configure which elements (line numbers, file headers, grid borders, Git modifica
|
|||
of components to display (e.g. 'numbers,changes,grid') or a pre\-defined style ('full').
|
||||
To set a default style, add the '\-\-style=".."' option to the configuration file or
|
||||
export the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). Possible
|
||||
values: *full*, auto, plain, changes, header, header-filename, header-filesize, grid,
|
||||
values: *default*, full, auto, plain, changes, header, header-filename, header-filesize, grid,
|
||||
rule, numbers, snip.
|
||||
.HP
|
||||
\fB\-r\fR, \fB\-\-line\-range\fR <N:M>...
|
||||
|
|
|
@ -322,7 +322,7 @@ impl App {
|
|||
.collect::<Vec<_>>()
|
||||
})
|
||||
.or(env_style_components)
|
||||
.unwrap_or_else(|| vec![StyleComponent::Full])
|
||||
.unwrap_or_else(|| vec![StyleComponent::Default])
|
||||
.into_iter()
|
||||
.map(|style| style.components(self.interactive_output))
|
||||
.fold(HashSet::new(), |mut acc, components| {
|
||||
|
|
|
@ -398,6 +398,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||
!&[
|
||||
"auto",
|
||||
"full",
|
||||
"default",
|
||||
"plain",
|
||||
"header",
|
||||
"header-filename",
|
||||
|
@ -419,7 +420,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||
})
|
||||
.help(
|
||||
"Comma-separated list of style elements to display \
|
||||
(*auto*, full, plain, changes, header, grid, rule, numbers, snip).",
|
||||
(*default*, auto, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).",
|
||||
)
|
||||
.long_help(
|
||||
"Configure which elements (line numbers, file headers, grid \
|
||||
|
@ -430,8 +431,9 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||
'--style=\"..\"' option to the configuration file or export the \
|
||||
BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\
|
||||
Possible values:\n\n \
|
||||
* full: enables all available components (default).\n \
|
||||
* auto: same as 'full', unless the output is piped.\n \
|
||||
* default: enables recommended style components (default).\n \
|
||||
* full: enables all available components.\n \
|
||||
* auto: same as 'default', unless the output is piped.\n \
|
||||
* plain: disables all available components.\n \
|
||||
* changes: show Git modification markers.\n \
|
||||
* header: alias for 'header-filename'.\n \
|
||||
|
|
12
src/style.rs
12
src/style.rs
|
@ -17,6 +17,7 @@ pub enum StyleComponent {
|
|||
LineNumbers,
|
||||
Snip,
|
||||
Full,
|
||||
Default,
|
||||
Plain,
|
||||
}
|
||||
|
||||
|
@ -25,7 +26,7 @@ impl StyleComponent {
|
|||
match self {
|
||||
StyleComponent::Auto => {
|
||||
if interactive_terminal {
|
||||
StyleComponent::Full.components(interactive_terminal)
|
||||
StyleComponent::Default.components(interactive_terminal)
|
||||
} else {
|
||||
StyleComponent::Plain.components(interactive_terminal)
|
||||
}
|
||||
|
@ -48,6 +49,14 @@ impl StyleComponent {
|
|||
StyleComponent::LineNumbers,
|
||||
StyleComponent::Snip,
|
||||
],
|
||||
StyleComponent::Default => &[
|
||||
#[cfg(feature = "git")]
|
||||
StyleComponent::Changes,
|
||||
StyleComponent::Grid,
|
||||
StyleComponent::HeaderFilename,
|
||||
StyleComponent::LineNumbers,
|
||||
StyleComponent::Snip,
|
||||
],
|
||||
StyleComponent::Plain => &[],
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +78,7 @@ impl FromStr for StyleComponent {
|
|||
"numbers" => Ok(StyleComponent::LineNumbers),
|
||||
"snip" => Ok(StyleComponent::Snip),
|
||||
"full" => Ok(StyleComponent::Full),
|
||||
"default" => Ok(StyleComponent::Default),
|
||||
"plain" => Ok(StyleComponent::Plain),
|
||||
_ => Err(format!("Unknown style '{}'", s).into()),
|
||||
}
|
||||
|
|
|
@ -974,6 +974,53 @@ fn header_full_binary() {
|
|||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn header_default() {
|
||||
bat()
|
||||
.arg("--paging=never")
|
||||
.arg("--color=never")
|
||||
.arg("--terminal-width=80")
|
||||
.arg("--wrap=never")
|
||||
.arg("--decorations=always")
|
||||
.arg("--style=default")
|
||||
.arg("single-line.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"\
|
||||
───────┬────────────────────────────────────────────────────────────────────────
|
||||
│ File: single-line.txt
|
||||
───────┼────────────────────────────────────────────────────────────────────────
|
||||
1 │ Single Line
|
||||
───────┴────────────────────────────────────────────────────────────────────────
|
||||
",
|
||||
)
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn header_default_is_default() {
|
||||
bat()
|
||||
.arg("--paging=never")
|
||||
.arg("--color=never")
|
||||
.arg("--terminal-width=80")
|
||||
.arg("--wrap=never")
|
||||
.arg("--decorations=always")
|
||||
.arg("single-line.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(
|
||||
"\
|
||||
───────┬────────────────────────────────────────────────────────────────────────
|
||||
│ File: single-line.txt
|
||||
───────┼────────────────────────────────────────────────────────────────────────
|
||||
1 │ Single Line
|
||||
───────┴────────────────────────────────────────────────────────────────────────
|
||||
",
|
||||
)
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filename_stdin() {
|
||||
bat()
|
||||
|
|
Loading…
Add table
Reference in a new issue