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

Add --no-single-file-header flag #1395

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl App {
}

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

let paging_mode = match self.matches.value_of("paging") {
Some("always") => PagingMode::Always,
Expand Down Expand Up @@ -282,7 +283,7 @@ impl App {
Ok(file_input)
}

fn style_components(&self) -> Result<StyleComponents> {
fn style_components(&self, single_file: bool) -> Result<StyleComponents> {
let matches = &self.matches;
let mut styled_components =
StyleComponents(if matches.value_of("decorations") == Some("never") {
Expand Down Expand Up @@ -330,6 +331,10 @@ impl App {
);
}

if single_file && matches.is_present("no-single-file-header") {
styled_components.0.remove(&StyleComponent::Header);
}

Ok(styled_components)
}
}
5 changes: 5 additions & 0 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
* snip: draw separation lines between distinct line ranges.",
),
)
.arg(
Arg::with_name("no-single-file-header")
.long("no-single-file-header")
.help("If set, no header will be shown if only a single file is displayed."),
)
.arg(
Arg::with_name("line-range")
.long("line-range")
Expand Down