Skip to content

Commit

Permalink
Move additional header fields to --style
Browse files Browse the repository at this point in the history
  • Loading branch information
mdibaiee committed Jan 3, 2022
1 parent 7d7c461 commit d57bed2
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 225 deletions.
37 changes: 0 additions & 37 deletions src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use bat::{
bat_warning,
config::{Config, VisibleLines},
error::*,
header::{HeaderComponent, HeaderComponents},
input::Input,
line_range::{HighlightedLineRanges, LineRange, LineRanges},
style::{StyleComponent, StyleComponents},
Expand Down Expand Up @@ -79,7 +78,6 @@ impl App {

pub fn config(&self, inputs: &[Input]) -> Result<Config> {
let style_components = self.style_components()?;
let header_components = self.header_components()?;

let paging_mode = match self.matches.value_of("paging") {
Some("always") => PagingMode::Always,
Expand Down Expand Up @@ -231,7 +229,6 @@ impl App {
),
},
style_components,
header_components,
syntax_mapping,
pager: self.matches.value_of("pager"),
use_italic_text: self.matches.value_of("italic-text") == Some("always"),
Expand Down Expand Up @@ -341,38 +338,4 @@ impl App {

Ok(styled_components)
}

fn header_components(&self) -> Result<HeaderComponents> {
let matches = &self.matches;
let header_components = HeaderComponents({
let env_header_components: Option<Vec<HeaderComponent>> = env::var("BAT_HEADER_INFO")
.ok()
.map(|header_str| {
header_str
.split(',')
.map(HeaderComponent::from_str)
.collect::<Result<Vec<HeaderComponent>>>()
})
.transpose()?;

matches
.values_of("header-info")
.map(|header| {
header
.map(|header| header.parse::<HeaderComponent>())
.filter_map(|header| header.ok())
.collect::<Vec<_>>()
})
.or(env_header_components)
.unwrap_or_else(|| vec![HeaderComponent::Filename])
.into_iter()
.map(|header| header.components())
.fold(Vec::new(), |mut acc, components| {
acc.extend(components.iter().cloned());
acc
})
});

Ok(header_components)
}
}
39 changes: 10 additions & 29 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bat::bat_warning;
use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
use once_cell::sync::Lazy;
use std::env;
Expand Down Expand Up @@ -369,33 +370,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.help("Display all supported highlighting themes.")
.long_help("Display a list of supported themes for syntax highlighting."),
)
.arg(
Arg::with_name("header-info")
.long("header-info")
.value_name("components")
.use_delimiter(true)
.takes_value(true)
.possible_values(&["full", "auto", "filename", "size", "last-modified", "permissions"])
.help(
"Comma-separated list of header information elements to display \
(full, filename, size, last-modified, permissions).",
)
.long_help(
"Configure what information (filename, file size, last modification date, \
permissions, ..) to display in the header.\
The argument is a comma-separated list of \
components to display (e.g. 'filename,size,last-modified') or all of them ('full'). \
To set a default set of header information, add the \
'--header-info=\"..\"' option to the configuration file or export the \
BAT_HEADER_INFO environment variable (e.g.: export BAT_HEADER_INFO=\"..\").\n\n\
Possible values:\n\n \
* full: enables all available components (default).\n \
* filename: displays the file name.\n \
* size: displays the size of the file in human-readable format.\n \
* last-modified: displays the last modification timestamp of the file.\n \
* permissions: displays the file owner, group and mode.",
),
)
.arg(
Arg::with_name("style")
.long("style")
Expand All @@ -411,13 +385,17 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.validator(|val| {
let mut invalid_vals = val.split(',').filter(|style| {
!&[
"auto", "full", "plain", "header", "grid", "rule", "numbers", "snip",
"auto", "full", "plain", "header", "filename", "filesize", "permissions", "lastmodified", "grid", "rule", "numbers", "snip",
#[cfg(feature = "git")]
"changes",
]
.contains(style)
});

if val.contains("header") {
bat_warning!("Style 'header' is deprecated, use 'filename' instead.");
}

if let Some(invalid) = invalid_vals.next() {
Err(format!("Unknown style, '{}'", invalid))
} else {
Expand All @@ -441,7 +419,10 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
* auto: same as 'full', unless the output is piped.\n \
* plain: disables all available components.\n \
* changes: show Git modification markers.\n \
* header: show filenames before the content.\n \
* filename: displays the file name.\n \
* size: displays the size of the file in human-readable format.\n \
* last-modified: displays the last modification timestamp of the file.\n \
* permissions: displays the file owner, group and mode.\n \
* grid: vertical/horizontal lines to separate side bar\n \
and the header from the content.\n \
* rule: horizontal lines to delimit files.\n \
Expand Down
4 changes: 0 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::header::HeaderComponents;
use crate::line_range::{HighlightedLineRanges, LineRanges};
#[cfg(feature = "paging")]
use crate::paging::PagingMode;
Expand Down Expand Up @@ -59,9 +58,6 @@ pub struct Config<'a> {
/// Style elements (grid, line numbers, ...)
pub style_components: StyleComponents,

/// Header elements (filename, size, ...)
pub header_components: HeaderComponents,

/// If and how text should be wrapped
pub wrapping_mode: WrappingMode,

Expand Down
88 changes: 0 additions & 88 deletions src/header.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod controller;
mod decorations;
mod diff;
pub mod error;
pub mod header;
pub mod input;
mod less;
pub mod line_range;
Expand Down
Loading

0 comments on commit d57bed2

Please sign in to comment.