Skip to content

Commit 3329a8f

Browse files
committed
refactor: remove last-modified and permissions, simplify header
1 parent 61e7f44 commit 3329a8f

25 files changed

+39
-141
lines changed

Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ dirs-next = { version = "2.0.0", optional = true }
6565
grep-cli = { version = "0.1.6", optional = true }
6666
regex = { version = "1.0", optional = true }
6767
walkdir = { version = "2.0", optional = true }
68-
time = { version = "0.3.5", features = ["formatting"] }
6968
bytesize = {version = "1.1.0", features = ["serde"]}
7069

7170
[dependencies.git2]

src/bin/bat/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl App {
322322
.collect::<Vec<_>>()
323323
})
324324
.or(env_style_components)
325-
.unwrap_or_else(|| vec![StyleComponent::Auto])
325+
.unwrap_or_else(|| vec![StyleComponent::Full])
326326
.into_iter()
327327
.map(|style| style.components(self.interactive_output))
328328
.fold(HashSet::new(), |mut acc, components| {

src/bin/bat/clap_app.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,8 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
400400
"full",
401401
"plain",
402402
"header",
403-
"header-full",
404403
"header-filename",
405404
"header-filesize",
406-
"header-permissions",
407-
"header-lastmodified",
408405
"grid",
409406
"rule",
410407
"numbers",
@@ -433,17 +430,13 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
433430
'--style=\"..\"' option to the configuration file or export the \
434431
BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\
435432
Possible values:\n\n \
436-
* auto: enables all components and 'header', unless the output is piped.
437-
* (default)\n \
438-
* full: enables all available components.\n \
433+
* full: enables all available components (default).\n \
434+
* auto: same as 'full', unless the output is piped.\n \
439435
* plain: disables all available components.\n \
440436
* changes: show Git modification markers.\n \
441-
* header: displays the filename and filesize.\n \
442-
* header-full: displays all header-* fields.\n \
437+
* header: show filenames before the content.\n \
443438
* header-filename: displays the file name.\n \
444439
* header-filesize: displays the size of the file in human-readable format.\n \
445-
* header-last-modified: displays the last modification timestamp of the file.\n \
446-
* header-permissions: displays the file owner, group and mode.\n \
447440
* grid: vertical/horizontal lines to separate side bar\n \
448441
and the header from the content.\n \
449442
* rule: horizontal lines to delimit files.\n \

src/input.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use std::convert::TryFrom;
22
use std::fs;
33
use std::fs::File;
44
use std::io::{self, BufRead, BufReader, Read};
5-
#[cfg(unix)]
6-
use std::os::unix::fs::PermissionsExt;
75
use std::path::{Path, PathBuf};
8-
use std::time::SystemTime;
96

107
use clircle::{Clircle, Identifier};
118
use content_inspector::{self, ContentType};
@@ -88,17 +85,10 @@ impl<'a> InputKind<'a> {
8885
}
8986
}
9087

91-
#[derive(Clone)]
92-
pub(crate) struct InputPermissions {
93-
pub(crate) mode: u32,
94-
}
95-
9688
#[derive(Clone, Default)]
9789
pub(crate) struct InputMetadata {
9890
pub(crate) user_provided_name: Option<PathBuf>,
99-
pub(crate) size: Option<u64>,
100-
pub(crate) permissions: Option<InputPermissions>,
101-
pub(crate) modified: Option<SystemTime>,
91+
pub(crate) size: Option<u64>
10292
}
10393

10494
pub struct Input<'a> {
@@ -140,32 +130,14 @@ impl<'a> Input<'a> {
140130
Self::_ordinary_file(path.as_ref())
141131
}
142132

143-
#[cfg(unix)]
144-
fn _input_permissions_os(metadata: fs::Metadata) -> Option<InputPermissions> {
145-
Some(InputPermissions {
146-
// the 3 digits from right are the familiar mode bits
147-
// we are looking for
148-
mode: metadata.permissions().mode() & 0o777,
149-
})
150-
}
151-
152-
#[cfg(not(unix))]
153-
fn _input_permissions_os(_metadata: fs::Metadata) -> Option<InputPermissions> {
154-
None
155-
}
156-
157133
fn _ordinary_file(path: &Path) -> Self {
158134
let kind = InputKind::OrdinaryFile(path.to_path_buf());
159135
let metadata = match fs::metadata(path.to_path_buf()) {
160136
Ok(meta) => {
161137
let size = meta.len();
162-
let modified = meta.modified().ok();
163-
let permissions = Self::_input_permissions_os(meta);
164138

165139
InputMetadata {
166140
size: Some(size),
167-
modified,
168-
permissions,
169141
..InputMetadata::default()
170142
}
171143
}

src/printer.rs

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use ansi_term::Colour::{Fixed, Green, Red, Yellow};
55
use ansi_term::Style;
66

77
use bytesize::ByteSize;
8-
use time::{format_description, OffsetDateTime};
98

109
use console::AnsiCodeIterator;
1110

@@ -298,7 +297,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
298297
if add_header_padding && !self.config.style_components.rule() {
299298
writeln!(handle)?;
300299
}
301-
write!(handle, "{}", " ".repeat(self.panel_width))?;
302300
}
303301

304302
let mode = match self.content_type {
@@ -322,15 +320,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
322320
(
323321
StyleComponent::HeaderFilesize,
324322
self.config.style_components.header_filesize(),
325-
),
326-
(
327-
StyleComponent::HeaderPermissions,
328-
self.config.style_components.header_permissions(),
329-
),
330-
(
331-
StyleComponent::HeaderLastModified,
332-
self.config.style_components.header_last_modified(),
333-
),
323+
)
334324
]
335325
.iter()
336326
.filter(|(_, is_enabled)| *is_enabled)
@@ -347,7 +337,9 @@ impl<'a> Printer for InteractivePrinter<'a> {
347337
.grid
348338
.paint(if self.panel_width > 0 { "│ " } else { "" }),
349339
)?;
350-
};
340+
} else {
341+
write!(handle, "{}", " ".repeat(self.panel_width))?;
342+
}
351343

352344
match component {
353345
StyleComponent::HeaderFilename => writeln!(
@@ -368,41 +360,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
368360
.unwrap_or("".into());
369361
writeln!(handle, "Size: {}", self.colors.header_value.paint(bsize))
370362
}
371-
372-
StyleComponent::HeaderPermissions => {
373-
let fmt_perms = format!(
374-
"{:o}",
375-
metadata
376-
.permissions
377-
.clone()
378-
.map(|perm| perm.mode)
379-
.unwrap_or(0)
380-
);
381-
writeln!(
382-
handle,
383-
"Permissions: {}",
384-
self.colors.header_value.paint(fmt_perms)
385-
)
386-
}
387-
388-
StyleComponent::HeaderLastModified => {
389-
let format = format_description::parse(
390-
"[day] [month repr:short] [year] [hour]:[minute]:[second]",
391-
)
392-
.unwrap();
393-
let fmt_modified = metadata
394-
.modified
395-
.map(|t| OffsetDateTime::from(t).format(&format).unwrap());
396-
397-
writeln!(
398-
handle,
399-
"Modified: {}",
400-
self.colors
401-
.header_value
402-
.paint(fmt_modified.unwrap_or("".into()))
403-
)
404-
}
405-
406363
_ => Ok(()),
407364
}
408365
})?;

src/style.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ pub enum StyleComponent {
1111
Grid,
1212
Rule,
1313
Header,
14-
HeaderFull,
1514
HeaderFilename,
1615
HeaderFilesize,
17-
HeaderPermissions,
18-
HeaderLastModified,
1916
LineNumbers,
2017
Snip,
2118
Full,
@@ -27,15 +24,7 @@ impl StyleComponent {
2724
match self {
2825
StyleComponent::Auto => {
2926
if interactive_terminal {
30-
&[
31-
#[cfg(feature = "git")]
32-
StyleComponent::Changes,
33-
StyleComponent::Grid,
34-
StyleComponent::HeaderFilename,
35-
StyleComponent::HeaderFilesize,
36-
StyleComponent::LineNumbers,
37-
StyleComponent::Snip,
38-
]
27+
StyleComponent::Full.components(interactive_terminal)
3928
} else {
4029
StyleComponent::Plain.components(interactive_terminal)
4130
}
@@ -46,18 +35,9 @@ impl StyleComponent {
4635
StyleComponent::Rule => &[StyleComponent::Rule],
4736
StyleComponent::Header => &[
4837
StyleComponent::HeaderFilename,
49-
StyleComponent::HeaderFilesize,
50-
],
51-
StyleComponent::HeaderFull => &[
52-
StyleComponent::HeaderFilename,
53-
StyleComponent::HeaderFilesize,
54-
StyleComponent::HeaderPermissions,
55-
StyleComponent::HeaderLastModified,
5638
],
5739
StyleComponent::HeaderFilename => &[StyleComponent::HeaderFilename],
5840
StyleComponent::HeaderFilesize => &[StyleComponent::HeaderFilesize],
59-
StyleComponent::HeaderPermissions => &[StyleComponent::HeaderPermissions],
60-
StyleComponent::HeaderLastModified => &[StyleComponent::HeaderLastModified],
6141
StyleComponent::LineNumbers => &[StyleComponent::LineNumbers],
6242
StyleComponent::Snip => &[StyleComponent::Snip],
6343
StyleComponent::Full => &[
@@ -66,8 +46,6 @@ impl StyleComponent {
6646
StyleComponent::Grid,
6747
StyleComponent::HeaderFilename,
6848
StyleComponent::HeaderFilesize,
69-
StyleComponent::HeaderPermissions,
70-
StyleComponent::HeaderLastModified,
7149
StyleComponent::LineNumbers,
7250
StyleComponent::Snip,
7351
],
@@ -87,11 +65,8 @@ impl FromStr for StyleComponent {
8765
"grid" => Ok(StyleComponent::Grid),
8866
"rule" => Ok(StyleComponent::Rule),
8967
"header" => Ok(StyleComponent::Header),
90-
"header-full" => Ok(StyleComponent::HeaderFull),
9168
"header-filename" => Ok(StyleComponent::HeaderFilename),
9269
"header-filesize" => Ok(StyleComponent::HeaderFilesize),
93-
"header-permissions" => Ok(StyleComponent::HeaderPermissions),
94-
"header-lastmodified" => Ok(StyleComponent::HeaderLastModified),
9570
"numbers" => Ok(StyleComponent::LineNumbers),
9671
"snip" => Ok(StyleComponent::Snip),
9772
"full" => Ok(StyleComponent::Full),
@@ -125,8 +100,6 @@ impl StyleComponents {
125100
pub fn header(&self) -> bool {
126101
self.header_filename()
127102
|| self.header_filesize()
128-
|| self.header_permissions()
129-
|| self.header_last_modified()
130103
}
131104

132105
pub fn header_filename(&self) -> bool {
@@ -137,14 +110,6 @@ impl StyleComponents {
137110
self.0.contains(&StyleComponent::HeaderFilesize)
138111
}
139112

140-
pub fn header_permissions(&self) -> bool {
141-
self.0.contains(&StyleComponent::HeaderPermissions)
142-
}
143-
144-
pub fn header_last_modified(&self) -> bool {
145-
self.0.contains(&StyleComponent::HeaderLastModified)
146-
}
147-
148113
pub fn numbers(&self) -> bool {
149114
self.0.contains(&StyleComponent::LineNumbers)
150115
}

0 commit comments

Comments
 (0)