diff --git a/Cargo.lock b/Cargo.lock index 286b3258d5..ce076fcb82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,7 +106,6 @@ dependencies = [ "syntect", "tempfile", "thiserror", - "time", "unicode-width", "wait-timeout", "walkdir", @@ -165,12 +164,6 @@ dependencies = [ "sys-info", ] -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - [[package]] name = "bytesize" version = "1.1.0" @@ -181,7 +174,6 @@ dependencies = [ ] [[package]] ->>>>>>> Add --header-info option to show more information about file in header name = "cc" version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index f2137acdf5..e7b1edbf97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,6 @@ dirs-next = { version = "2.0.0", optional = true } grep-cli = { version = "0.1.6", optional = true } regex = { version = "1.0", optional = true } walkdir = { version = "2.0", optional = true } -time = { version = "0.3.5", features = ["formatting"] } bytesize = {version = "1.1.0", features = ["serde"]} [dependencies.git2] diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 61732354a6..79c11caefe 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -400,11 +400,8 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { "full", "plain", "header", - "header-full", "header-filename", "header-filesize", - "header-permissions", - "header-lastmodified", "grid", "rule", "numbers", @@ -433,17 +430,13 @@ 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 \ - * auto: enables all components and 'header', unless the output is piped. - * (default)\n \ - * full: enables all available components.\n \ + * full: enables all available components (default).\n \ + * auto: same as 'full', unless the output is piped.\n \ * plain: disables all available components.\n \ * changes: show Git modification markers.\n \ - * header: displays the filename and filesize.\n \ - * header-full: displays all header-* fields.\n \ + * header: displays the filename.\n \ * header-filename: displays the file name.\n \ * header-filesize: displays the size of the file in human-readable format.\n \ - * header-last-modified: displays the last modification timestamp of the file.\n \ - * header-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 \ diff --git a/src/input.rs b/src/input.rs index fc2e1e5646..fe5eea75e0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -3,9 +3,7 @@ use std::fs; use std::fs::File; use std::io::{self, BufRead, BufReader, Read}; #[cfg(unix)] -use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; -use std::time::SystemTime; use clircle::{Clircle, Identifier}; use content_inspector::{self, ContentType}; @@ -88,17 +86,10 @@ impl<'a> InputKind<'a> { } } -#[derive(Clone)] -pub(crate) struct InputPermissions { - pub(crate) mode: u32, -} - #[derive(Clone, Default)] pub(crate) struct InputMetadata { pub(crate) user_provided_name: Option, - pub(crate) size: Option, - pub(crate) permissions: Option, - pub(crate) modified: Option, + pub(crate) size: Option } pub struct Input<'a> { @@ -140,32 +131,14 @@ impl<'a> Input<'a> { Self::_ordinary_file(path.as_ref()) } - #[cfg(unix)] - fn _input_permissions_os(metadata: fs::Metadata) -> Option { - Some(InputPermissions { - // the 3 digits from right are the familiar mode bits - // we are looking for - mode: metadata.permissions().mode() & 0o777, - }) - } - - #[cfg(not(unix))] - fn _input_permissions_os(_metadata: fs::Metadata) -> Option { - None - } - fn _ordinary_file(path: &Path) -> Self { let kind = InputKind::OrdinaryFile(path.to_path_buf()); let metadata = match fs::metadata(path.to_path_buf()) { Ok(meta) => { let size = meta.len(); - let modified = meta.modified().ok(); - let permissions = Self::_input_permissions_os(meta); InputMetadata { size: Some(size), - modified, - permissions, ..InputMetadata::default() } } diff --git a/src/printer.rs b/src/printer.rs index 623cc57a5d..004465fc10 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -5,7 +5,6 @@ use ansi_term::Colour::{Fixed, Green, Red, Yellow}; use ansi_term::Style; use bytesize::ByteSize; -use time::{format_description, OffsetDateTime}; use console::AnsiCodeIterator; @@ -298,7 +297,6 @@ impl<'a> Printer for InteractivePrinter<'a> { if add_header_padding && !self.config.style_components.rule() { writeln!(handle)?; } - write!(handle, "{}", " ".repeat(self.panel_width))?; } let mode = match self.content_type { @@ -322,15 +320,7 @@ impl<'a> Printer for InteractivePrinter<'a> { ( StyleComponent::HeaderFilesize, self.config.style_components.header_filesize(), - ), - ( - StyleComponent::HeaderPermissions, - self.config.style_components.header_permissions(), - ), - ( - StyleComponent::HeaderLastModified, - self.config.style_components.header_last_modified(), - ), + ) ] .iter() .filter(|(_, is_enabled)| *is_enabled) @@ -347,7 +337,9 @@ impl<'a> Printer for InteractivePrinter<'a> { .grid .paint(if self.panel_width > 0 { "│ " } else { "" }), )?; - }; + } else { + write!(handle, "{}", " ".repeat(self.panel_width))?; + } match component { StyleComponent::HeaderFilename => writeln!( @@ -368,41 +360,6 @@ impl<'a> Printer for InteractivePrinter<'a> { .unwrap_or("".into()); writeln!(handle, "Size: {}", self.colors.header_value.paint(bsize)) } - - 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( - "[day] [month repr:short] [year] [hour]:[minute]:[second]", - ) - .unwrap(); - let fmt_modified = metadata - .modified - .map(|t| OffsetDateTime::from(t).format(&format).unwrap()); - - writeln!( - handle, - "Modified: {}", - self.colors - .header_value - .paint(fmt_modified.unwrap_or("".into())) - ) - } - _ => Ok(()), } })?; diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 5648f252cd..edc47210f8 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -919,7 +919,7 @@ fn empty_file_leads_to_empty_output_with_rule_enabled() { } #[test] -fn filename_basic() { +fn header_basic() { bat() .arg("test.txt") .arg("--decorations=always") @@ -928,12 +928,12 @@ fn filename_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\n") + .stdout("File: foo\nSize: 12 B\n") .stderr(""); } #[test] -fn filename_binary() { +fn header_binary() { bat() .arg("test.binary") .arg("--decorations=always") @@ -942,7 +942,7 @@ fn filename_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo \n") + .stdout("File: foo \nSize: 4 B\n") .stderr(""); } @@ -950,7 +950,7 @@ fn filename_binary() { fn filename_stdin() { bat() .arg("--decorations=always") - .arg("--style=header") + .arg("--style=header-filename") .arg("-r=0:0") .arg("-") .write_stdin("stdin\n") @@ -966,7 +966,7 @@ fn filename_stdin_binary() { let vec = vec![0; 1]; bat_with_config() .arg("--decorations=always") - .arg("--style=header") + .arg("--style=header-filename") .write_stdin(vec) .arg("--file-name=foo") .assert() @@ -979,7 +979,7 @@ fn filename_stdin_binary() { fn filename_multiple_ok() { bat() .arg("--decorations=always") - .arg("--style=header") + .arg("--style=header-filename") .arg("-r=0:0") .arg("test.txt") .arg("--file-name=foo") @@ -995,7 +995,7 @@ fn filename_multiple_ok() { fn filename_multiple_err() { bat() .arg("--decorations=always") - .arg("--style=header") + .arg("--style=header-filename") .arg("-r=0:0") .arg("test.txt") .arg("--file-name=foo") @@ -1012,7 +1012,7 @@ fn header_padding() { .arg("test.txt") .arg("single-line.txt") .assert() - .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n") + .stdout("File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n") .stderr(""); } @@ -1027,9 +1027,11 @@ fn header_padding_rule() { .assert() .stdout( "File: test.txt +Size: 12 B hello world ──────────────────────────────────────────────────────────────────────────────── File: single-line.txt +Size: 11 B Single Line ", ) @@ -1219,6 +1221,7 @@ fn grid_for_file_without_newline() { "\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt + │ Size: 11 B ───────┼──────────────────────────────────────────────────────────────────────── 1 │ Single Line ───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/changes_grid_header.snapshot.txt b/tests/snapshots/output/changes_grid_header.snapshot.txt index 98518e196e..afd82d70b0 100644 --- a/tests/snapshots/output/changes_grid_header.snapshot.txt +++ b/tests/snapshots/output/changes_grid_header.snapshot.txt @@ -1,5 +1,6 @@ ──┬───────────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ──┼───────────────────────────────────────────────────────────────────────────── + │ /// A rectangle. First line is changed to prevent a regression of #1869 │ struct Rectangle { diff --git a/tests/snapshots/output/changes_grid_header_numbers.snapshot.txt b/tests/snapshots/output/changes_grid_header_numbers.snapshot.txt index f8ecaa32c3..924b65dafb 100644 --- a/tests/snapshots/output/changes_grid_header_numbers.snapshot.txt +++ b/tests/snapshots/output/changes_grid_header_numbers.snapshot.txt @@ -1,5 +1,6 @@ ───────┬──────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ───────┼──────────────────────────────────────────────────────────────────────── 1 + │ /// A rectangle. First line is changed to prevent a regression of #1869 2 │ struct Rectangle { diff --git a/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt index f8ecaa32c3..924b65dafb 100644 --- a/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt +++ b/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt @@ -1,5 +1,6 @@ ───────┬──────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ───────┼──────────────────────────────────────────────────────────────────────── 1 + │ /// A rectangle. First line is changed to prevent a regression of #1869 2 │ struct Rectangle { diff --git a/tests/snapshots/output/changes_grid_header_rule.snapshot.txt b/tests/snapshots/output/changes_grid_header_rule.snapshot.txt index 98518e196e..afd82d70b0 100644 --- a/tests/snapshots/output/changes_grid_header_rule.snapshot.txt +++ b/tests/snapshots/output/changes_grid_header_rule.snapshot.txt @@ -1,5 +1,6 @@ ──┬───────────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ──┼───────────────────────────────────────────────────────────────────────────── + │ /// A rectangle. First line is changed to prevent a regression of #1869 │ struct Rectangle { diff --git a/tests/snapshots/output/changes_header.snapshot.txt b/tests/snapshots/output/changes_header.snapshot.txt index d5c1afd920..0863e2abdd 100644 --- a/tests/snapshots/output/changes_header.snapshot.txt +++ b/tests/snapshots/output/changes_header.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B + /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { width: u32, diff --git a/tests/snapshots/output/changes_header_numbers.snapshot.txt b/tests/snapshots/output/changes_header_numbers.snapshot.txt index cc99df08b3..cd0393e5a7 100644 --- a/tests/snapshots/output/changes_header_numbers.snapshot.txt +++ b/tests/snapshots/output/changes_header_numbers.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B 1 + /// A rectangle. First line is changed to prevent a regression of #1869 2 struct Rectangle { 3 width: u32, diff --git a/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt index cc99df08b3..cd0393e5a7 100644 --- a/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt +++ b/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B 1 + /// A rectangle. First line is changed to prevent a regression of #1869 2 struct Rectangle { 3 width: u32, diff --git a/tests/snapshots/output/changes_header_rule.snapshot.txt b/tests/snapshots/output/changes_header_rule.snapshot.txt index d5c1afd920..0863e2abdd 100644 --- a/tests/snapshots/output/changes_header_rule.snapshot.txt +++ b/tests/snapshots/output/changes_header_rule.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B + /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { width: u32, diff --git a/tests/snapshots/output/full.snapshot.txt b/tests/snapshots/output/full.snapshot.txt index f8ecaa32c3..924b65dafb 100644 --- a/tests/snapshots/output/full.snapshot.txt +++ b/tests/snapshots/output/full.snapshot.txt @@ -1,5 +1,6 @@ ───────┬──────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ───────┼──────────────────────────────────────────────────────────────────────── 1 + │ /// A rectangle. First line is changed to prevent a regression of #1869 2 │ struct Rectangle { diff --git a/tests/snapshots/output/grid_header.snapshot.txt b/tests/snapshots/output/grid_header.snapshot.txt index 010e3a8137..bd4493ece9 100644 --- a/tests/snapshots/output/grid_header.snapshot.txt +++ b/tests/snapshots/output/grid_header.snapshot.txt @@ -1,5 +1,6 @@ ──────────────────────────────────────────────────────────────────────────────── File: sample.rs +Size: 533 B ──────────────────────────────────────────────────────────────────────────────── /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { diff --git a/tests/snapshots/output/grid_header_numbers.snapshot.txt b/tests/snapshots/output/grid_header_numbers.snapshot.txt index dfbb934bb7..dba0f16687 100644 --- a/tests/snapshots/output/grid_header_numbers.snapshot.txt +++ b/tests/snapshots/output/grid_header_numbers.snapshot.txt @@ -1,5 +1,6 @@ ─────┬────────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ─────┼────────────────────────────────────────────────────────────────────────── 1 │ /// A rectangle. First line is changed to prevent a regression of #1869 2 │ struct Rectangle { diff --git a/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt b/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt index dfbb934bb7..dba0f16687 100644 --- a/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt +++ b/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt @@ -1,5 +1,6 @@ ─────┬────────────────────────────────────────────────────────────────────────── │ File: sample.rs + │ Size: 533 B ─────┼────────────────────────────────────────────────────────────────────────── 1 │ /// A rectangle. First line is changed to prevent a regression of #1869 2 │ struct Rectangle { diff --git a/tests/snapshots/output/grid_header_rule.snapshot.txt b/tests/snapshots/output/grid_header_rule.snapshot.txt index 010e3a8137..bd4493ece9 100644 --- a/tests/snapshots/output/grid_header_rule.snapshot.txt +++ b/tests/snapshots/output/grid_header_rule.snapshot.txt @@ -1,5 +1,6 @@ ──────────────────────────────────────────────────────────────────────────────── File: sample.rs +Size: 533 B ──────────────────────────────────────────────────────────────────────────────── /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { diff --git a/tests/snapshots/output/header.snapshot.txt b/tests/snapshots/output/header.snapshot.txt index 3cbbad49d2..768c9ae9e5 100644 --- a/tests/snapshots/output/header.snapshot.txt +++ b/tests/snapshots/output/header.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs +Size: 533 B /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { width: u32, diff --git a/tests/snapshots/output/header_numbers.snapshot.txt b/tests/snapshots/output/header_numbers.snapshot.txt index 82fa9175a5..339de71d2a 100644 --- a/tests/snapshots/output/header_numbers.snapshot.txt +++ b/tests/snapshots/output/header_numbers.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B 1 /// A rectangle. First line is changed to prevent a regression of #1869 2 struct Rectangle { 3 width: u32, diff --git a/tests/snapshots/output/header_numbers_rule.snapshot.txt b/tests/snapshots/output/header_numbers_rule.snapshot.txt index 82fa9175a5..339de71d2a 100644 --- a/tests/snapshots/output/header_numbers_rule.snapshot.txt +++ b/tests/snapshots/output/header_numbers_rule.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs + Size: 533 B 1 /// A rectangle. First line is changed to prevent a regression of #1869 2 struct Rectangle { 3 width: u32, diff --git a/tests/snapshots/output/header_rule.snapshot.txt b/tests/snapshots/output/header_rule.snapshot.txt index 3cbbad49d2..768c9ae9e5 100644 --- a/tests/snapshots/output/header_rule.snapshot.txt +++ b/tests/snapshots/output/header_rule.snapshot.txt @@ -1,4 +1,5 @@ File: sample.rs +Size: 533 B /// A rectangle. First line is changed to prevent a regression of #1869 struct Rectangle { width: u32,