Skip to content

Commit d57bed2

Browse files
committed
Move additional header fields to --style
1 parent 7d7c461 commit d57bed2

File tree

7 files changed

+128
-225
lines changed

7 files changed

+128
-225
lines changed

src/bin/bat/app.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use bat::{
1919
bat_warning,
2020
config::{Config, VisibleLines},
2121
error::*,
22-
header::{HeaderComponent, HeaderComponents},
2322
input::Input,
2423
line_range::{HighlightedLineRanges, LineRange, LineRanges},
2524
style::{StyleComponent, StyleComponents},
@@ -79,7 +78,6 @@ impl App {
7978

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

8482
let paging_mode = match self.matches.value_of("paging") {
8583
Some("always") => PagingMode::Always,
@@ -231,7 +229,6 @@ impl App {
231229
),
232230
},
233231
style_components,
234-
header_components,
235232
syntax_mapping,
236233
pager: self.matches.value_of("pager"),
237234
use_italic_text: self.matches.value_of("italic-text") == Some("always"),
@@ -341,38 +338,4 @@ impl App {
341338

342339
Ok(styled_components)
343340
}
344-
345-
fn header_components(&self) -> Result<HeaderComponents> {
346-
let matches = &self.matches;
347-
let header_components = HeaderComponents({
348-
let env_header_components: Option<Vec<HeaderComponent>> = env::var("BAT_HEADER_INFO")
349-
.ok()
350-
.map(|header_str| {
351-
header_str
352-
.split(',')
353-
.map(HeaderComponent::from_str)
354-
.collect::<Result<Vec<HeaderComponent>>>()
355-
})
356-
.transpose()?;
357-
358-
matches
359-
.values_of("header-info")
360-
.map(|header| {
361-
header
362-
.map(|header| header.parse::<HeaderComponent>())
363-
.filter_map(|header| header.ok())
364-
.collect::<Vec<_>>()
365-
})
366-
.or(env_header_components)
367-
.unwrap_or_else(|| vec![HeaderComponent::Filename])
368-
.into_iter()
369-
.map(|header| header.components())
370-
.fold(Vec::new(), |mut acc, components| {
371-
acc.extend(components.iter().cloned());
372-
acc
373-
})
374-
});
375-
376-
Ok(header_components)
377-
}
378341
}

src/bin/bat/clap_app.rs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bat::bat_warning;
12
use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
23
use once_cell::sync::Lazy;
34
use std::env;
@@ -369,33 +370,6 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
369370
.help("Display all supported highlighting themes.")
370371
.long_help("Display a list of supported themes for syntax highlighting."),
371372
)
372-
.arg(
373-
Arg::with_name("header-info")
374-
.long("header-info")
375-
.value_name("components")
376-
.use_delimiter(true)
377-
.takes_value(true)
378-
.possible_values(&["full", "auto", "filename", "size", "last-modified", "permissions"])
379-
.help(
380-
"Comma-separated list of header information elements to display \
381-
(full, filename, size, last-modified, permissions).",
382-
)
383-
.long_help(
384-
"Configure what information (filename, file size, last modification date, \
385-
permissions, ..) to display in the header.\
386-
The argument is a comma-separated list of \
387-
components to display (e.g. 'filename,size,last-modified') or all of them ('full'). \
388-
To set a default set of header information, add the \
389-
'--header-info=\"..\"' option to the configuration file or export the \
390-
BAT_HEADER_INFO environment variable (e.g.: export BAT_HEADER_INFO=\"..\").\n\n\
391-
Possible values:\n\n \
392-
* full: enables all available components (default).\n \
393-
* filename: displays the file name.\n \
394-
* size: displays the size of the file in human-readable format.\n \
395-
* last-modified: displays the last modification timestamp of the file.\n \
396-
* permissions: displays the file owner, group and mode.",
397-
),
398-
)
399373
.arg(
400374
Arg::with_name("style")
401375
.long("style")
@@ -411,13 +385,17 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
411385
.validator(|val| {
412386
let mut invalid_vals = val.split(',').filter(|style| {
413387
!&[
414-
"auto", "full", "plain", "header", "grid", "rule", "numbers", "snip",
388+
"auto", "full", "plain", "header", "filename", "filesize", "permissions", "lastmodified", "grid", "rule", "numbers", "snip",
415389
#[cfg(feature = "git")]
416390
"changes",
417391
]
418392
.contains(style)
419393
});
420394

395+
if val.contains("header") {
396+
bat_warning!("Style 'header' is deprecated, use 'filename' instead.");
397+
}
398+
421399
if let Some(invalid) = invalid_vals.next() {
422400
Err(format!("Unknown style, '{}'", invalid))
423401
} else {
@@ -441,7 +419,10 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
441419
* auto: same as 'full', unless the output is piped.\n \
442420
* plain: disables all available components.\n \
443421
* changes: show Git modification markers.\n \
444-
* header: show filenames before the content.\n \
422+
* filename: displays the file name.\n \
423+
* size: displays the size of the file in human-readable format.\n \
424+
* last-modified: displays the last modification timestamp of the file.\n \
425+
* permissions: displays the file owner, group and mode.\n \
445426
* grid: vertical/horizontal lines to separate side bar\n \
446427
and the header from the content.\n \
447428
* rule: horizontal lines to delimit files.\n \

src/config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::header::HeaderComponents;
21
use crate::line_range::{HighlightedLineRanges, LineRanges};
32
#[cfg(feature = "paging")]
43
use crate::paging::PagingMode;
@@ -59,9 +58,6 @@ pub struct Config<'a> {
5958
/// Style elements (grid, line numbers, ...)
6059
pub style_components: StyleComponents,
6160

62-
/// Header elements (filename, size, ...)
63-
pub header_components: HeaderComponents,
64-
6561
/// If and how text should be wrapped
6662
pub wrapping_mode: WrappingMode,
6763

src/header.rs

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub mod controller;
3232
mod decorations;
3333
mod diff;
3434
pub mod error;
35-
pub mod header;
3635
pub mod input;
3736
mod less;
3837
pub mod line_range;

0 commit comments

Comments
 (0)