Skip to content

Commit

Permalink
header values in bold, auto = all with 'header'
Browse files Browse the repository at this point in the history
  • Loading branch information
mdibaiee committed Jan 9, 2022
1 parent c887411 commit 61e7f44
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl App {
.collect::<Vec<_>>()
})
.or(env_style_components)
.unwrap_or_else(|| vec![StyleComponent::Full])
.unwrap_or_else(|| vec![StyleComponent::Auto])
.into_iter()
.map(|style| style.components(self.interactive_output))
.fold(HashSet::new(), |mut acc, components| {
Expand Down
24 changes: 18 additions & 6 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,22 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.validator(|val| {
let mut invalid_vals = val.split(',').filter(|style| {
!&[
"auto", "full", "plain", "header", "header-full", "header-filename", "header-filesize", "header-permissions", "header-lastmodified", "grid", "rule", "numbers", "snip",
"auto",
"full",
"plain",
"header",
"header-full",
"header-filename",
"header-filesize",
"header-permissions",
"header-lastmodified",
"grid",
"rule",
"numbers",
"snip",
#[cfg(feature = "git")]
"changes",
]
.contains(style)
"changes",
].contains(style)
});

if let Some(invalid) = invalid_vals.next() {
Expand All @@ -422,8 +433,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 \
* auto: enables all components and 'header', unless the output is piped.
* (default)\n \
* full: enables all available components.\n \
* plain: disables all available components.\n \
* changes: show Git modification markers.\n \
* header: displays the filename and filesize.\n \
Expand Down
38 changes: 23 additions & 15 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
.kind()
.map(|kind| format!("{}: ", kind))
.unwrap_or_else(|| "".into()),
self.colors.filename.paint(description.title()),
self.colors.header_value.paint(description.title()),
mode
),

Expand All @@ -366,18 +366,24 @@ impl<'a> Printer for InteractivePrinter<'a> {
.size
.map(|s| format!("{}", ByteSize(s)))
.unwrap_or("".into());
writeln!(handle, "Size: {}", bsize)
writeln!(handle, "Size: {}", self.colors.header_value.paint(bsize))
}

StyleComponent::HeaderPermissions => writeln!(
handle,
"Permissions: {:o}",
metadata
.permissions
.clone()
.map(|perm| perm.mode)
.unwrap_or(0)
),
StyleComponent::HeaderPermissions => {
let fmt_perms = format!(
"{:o}",
metadata
.permissions
.clone()
.map(|perm| perm.mode)
.unwrap_or(0)
);
writeln!(
handle,
"Permissions: {}",
self.colors.header_value.paint(fmt_perms)
)
}

StyleComponent::HeaderLastModified => {
let format = format_description::parse(
Expand All @@ -390,8 +396,10 @@ impl<'a> Printer for InteractivePrinter<'a> {

writeln!(
handle,
"Last Modified At: {}",
fmt_modified.unwrap_or("".into())
"Modified: {}",
self.colors
.header_value
.paint(fmt_modified.unwrap_or("".into()))
)
}

Expand Down Expand Up @@ -689,7 +697,7 @@ const DEFAULT_GUTTER_COLOR: u8 = 238;
pub struct Colors {
pub grid: Style,
pub rule: Style,
pub filename: Style,
pub header_value: Style,
pub git_added: Style,
pub git_removed: Style,
pub git_modified: Style,
Expand Down Expand Up @@ -718,7 +726,7 @@ impl Colors {
Colors {
grid: gutter_style,
rule: gutter_style,
filename: Style::new().bold(),
header_value: Style::new().bold(),
git_added: Green.normal(),
git_removed: Red.normal(),
git_modified: Yellow.normal(),
Expand Down
10 changes: 9 additions & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ impl StyleComponent {
match self {
StyleComponent::Auto => {
if interactive_terminal {
StyleComponent::Full.components(interactive_terminal)
&[
#[cfg(feature = "git")]
StyleComponent::Changes,
StyleComponent::Grid,
StyleComponent::HeaderFilename,
StyleComponent::HeaderFilesize,
StyleComponent::LineNumbers,
StyleComponent::Snip,
]
} else {
StyleComponent::Plain.components(interactive_terminal)
}
Expand Down

0 comments on commit 61e7f44

Please sign in to comment.