on master help sign in
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

commitadea8950267e2f0d242d033a1ef3140702ad01a2 authorIsaac Horvath <isaac.horvath@gmail.com> dateWed 4 May 2022, 15:31 (5 years ago) parenta6bd28a
9 files changed+69−9
CHANGELOG.md+1 assets/completions/_bat.ps1.in+1−1 assets/completions/bat.fish.in+1−1 assets/completions/bat.zsh.in+1−1 assets/manual/bat.1.in+1−1 src/bin/bat/app.rs+1−1 src/bin/bat/clap_app.rs+5−3 src/style.rs+11−1 tests/integration_tests.rs+47
CHANGELOG.md+1
@@ -3,6 +3,7 @@
33## Features
44
55- Correctly render tab stops in --show-all, see #2038 (@Synthetica9)
6+- Add a `--style=default` option, less verbose than `full`, see #2061 (@IsaacHorvath)
67- Enable BusyBox less as pager, see #2162 (@nfisher1226)
78
89## Bugfixes
assets/completions/_bat.ps1.in+1−1
@@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
3737 [CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
3838 [CompletionResult]::new('--map-syntax', 'map-syntax', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
3939 [CompletionResult]::new('--theme', 'theme', [CompletionResultType]::ParameterName, 'Set the color theme for syntax highlighting.')
40− [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).')
40+ [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).')
4141 [CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
4242 [CompletionResult]::new('--line-range', 'line-range', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
4343 [CompletionResult]::new('-A', 'A', [CompletionResultType]::ParameterName, 'Show non-printable characters (space, tab, newline, ..).')
assets/completions/bat.fish.in+1−1
@@ -56,7 +56,7 @@ complete -c {{PROJECT_EXECUTABLE}} -s P -d "Disable paging. Alias for '--paging=
5656
5757complete -c {{PROJECT_EXECUTABLE}} -s A -l show-all -d "Show non-printable characters like space/tab/newline" -n "not __fish_seen_subcommand_from cache"
5858
59−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"
59+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"
6060
6161complete -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"
6262
assets/completions/bat.zsh.in+1−1
@@ -75,7 +75,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
7575 ;;
7676
7777 style)
78− _values -s , 'style' auto full plain changes header header-filename header-filesize grid rule numbers snip
78+ _values -s , 'style' default auto full plain changes header header-filename header-filesize grid rule numbers snip
7979 ;;
8080 esac
8181}
assets/manual/bat.1.in+1−1
@@ -146,7 +146,7 @@ Configure which elements (line numbers, file headers, grid borders, Git modifica
146146of components to display (e.g. 'numbers,changes,grid') or a pre\-defined style ('full').
147147To set a default style, add the '\-\-style=".."' option to the configuration file or
148148export the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). Possible
149−values: *full*, auto, plain, changes, header, header-filename, header-filesize, grid,
149+values: *default*, full, auto, plain, changes, header, header-filename, header-filesize, grid,
150150rule, numbers, snip.
151151.HP
152152\fB\-r\fR, \fB\-\-line\-range\fR <N:M>...
src/bin/bat/app.rs+1−1
@@ -322,7 +322,7 @@ impl App {
322322 .collect::<Vec<_>>()
323323 })
324324 .or(env_style_components)
325− .unwrap_or_else(|| vec![StyleComponent::Full])
325+ .unwrap_or_else(|| vec![StyleComponent::Default])
326326 .into_iter()
327327 .map(|style| style.components(self.interactive_output))
328328 .fold(HashSet::new(), |mut acc, components| {
src/bin/bat/clap_app.rs+5−3
@@ -398,6 +398,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
398398 !&[
399399 "auto",
400400 "full",
401+ "default",
401402 "plain",
402403 "header",
403404 "header-filename",
@@ -419,7 +420,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
419420 })
420421 .help(
421422 "Comma-separated list of style elements to display \
422− (*auto*, full, plain, changes, header, grid, rule, numbers, snip).",
423+ (*default*, auto, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).",
423424 )
424425 .long_help(
425426 "Configure which elements (line numbers, file headers, grid \
@@ -430,8 +431,9 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
430431 '--style=\"..\"' option to the configuration file or export the \
431432 BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\
432433 Possible values:\n\n \
433− * full: enables all available components (default).\n \
434− * auto: same as 'full', unless the output is piped.\n \
434+ * default: enables recommended style components (default).\n \
435+ * full: enables all available components.\n \
436+ * auto: same as 'default', unless the output is piped.\n \
435437 * plain: disables all available components.\n \
436438 * changes: show Git modification markers.\n \
437439 * header: alias for 'header-filename'.\n \
src/style.rs+11−1
@@ -17,6 +17,7 @@ pub enum StyleComponent {
1717 LineNumbers,
1818 Snip,
1919 Full,
20+ Default,
2021 Plain,
2122}
2223
@@ -25,7 +26,7 @@ impl StyleComponent {
2526 match self {
2627 StyleComponent::Auto => {
2728 if interactive_terminal {
28− StyleComponent::Full.components(interactive_terminal)
29+ StyleComponent::Default.components(interactive_terminal)
2930 } else {
3031 StyleComponent::Plain.components(interactive_terminal)
3132 }
@@ -48,6 +49,14 @@ impl StyleComponent {
4849 StyleComponent::LineNumbers,
4950 StyleComponent::Snip,
5051 ],
52+ StyleComponent::Default => &[
53+ #[cfg(feature = "git")]
54+ StyleComponent::Changes,
55+ StyleComponent::Grid,
56+ StyleComponent::HeaderFilename,
57+ StyleComponent::LineNumbers,
58+ StyleComponent::Snip,
59+ ],
5160 StyleComponent::Plain => &[],
5261 }
5362 }
@@ -69,6 +78,7 @@ impl FromStr for StyleComponent {
6978 "numbers" => Ok(StyleComponent::LineNumbers),
7079 "snip" => Ok(StyleComponent::Snip),
7180 "full" => Ok(StyleComponent::Full),
81+ "default" => Ok(StyleComponent::Default),
7282 "plain" => Ok(StyleComponent::Plain),
7383 _ => Err(format!("Unknown style '{}'", s).into()),
7484 }
tests/integration_tests.rs+47
@@ -974,6 +974,53 @@ fn header_full_binary() {
974974 .stderr("");
975975}
976976
977+#[test]
978+fn header_default() {
979+ bat()
980+ .arg("--paging=never")
981+ .arg("--color=never")
982+ .arg("--terminal-width=80")
983+ .arg("--wrap=never")
984+ .arg("--decorations=always")
985+ .arg("--style=default")
986+ .arg("single-line.txt")
987+ .assert()
988+ .success()
989+ .stdout(
990+ "\
991+───────┬────────────────────────────────────────────────────────────────────────
992+ │ File: single-line.txt
993+───────┼────────────────────────────────────────────────────────────────────────
994+ 1 │ Single Line
995+───────┴────────────────────────────────────────────────────────────────────────
996+",
997+ )
998+ .stderr("");
999+}
1000+
1001+#[test]
1002+fn header_default_is_default() {
1003+ bat()
1004+ .arg("--paging=never")
1005+ .arg("--color=never")
1006+ .arg("--terminal-width=80")
1007+ .arg("--wrap=never")
1008+ .arg("--decorations=always")
1009+ .arg("single-line.txt")
1010+ .assert()
1011+ .success()
1012+ .stdout(
1013+ "\
1014+───────┬────────────────────────────────────────────────────────────────────────
1015+ │ File: single-line.txt
1016+───────┼────────────────────────────────────────────────────────────────────────
1017+ 1 │ Single Line
1018+───────┴────────────────────────────────────────────────────────────────────────
1019+",
1020+ )
1021+ .stderr("");
1022+}
1023+
9771024#[test]
9781025fn filename_stdin() {
9791026 bat()