summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahdi Dibaiee <mdibaiee@pm.me>2022-02-07 19:48:57 +0000
committerGitHub <noreply@github.com>2022-02-07 20:48:57 +0100
commit312c8ef01f1a80f4a806629a7dacd32508b267a5 (patch)
tree27299be2d3bccaef527847f7d33ee765e6ff69cb
parentf3f819493208f32b7a1374578568970ec381f5ac (diff)
Add new `--style` called `header-filesize` and display it by default (#1988)
Also rename `header` to `header-filename`. Related to #1701
-rw-r--r--CHANGELOG.md2
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin/bat/clap_app.rs20
-rw-r--r--src/input.rs9
-rw-r--r--src/printer.rs104
-rw-r--r--src/style.rs22
-rw-r--r--tests/benchmarks/many-small-files/small-file-0.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-1.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-10.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-100.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-11.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-12.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-13.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-14.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-15.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-16.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-17.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-18.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-19.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-2.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-20.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-21.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-22.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-23.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-24.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-25.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-26.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-27.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-28.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-29.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-3.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-30.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-31.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-32.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-33.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-34.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-35.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-36.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-37.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-38.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-39.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-4.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-40.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-41.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-42.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-43.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-44.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-45.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-46.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-47.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-48.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-49.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-5.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-50.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-51.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-52.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-53.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-54.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-55.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-56.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-57.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-58.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-59.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-6.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-60.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-61.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-62.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-63.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-64.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-65.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-66.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-67.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-68.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-69.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-7.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-70.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-71.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-72.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-73.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-74.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-75.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-76.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-77.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-78.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-79.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-8.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-80.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-81.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-82.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-83.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-84.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-85.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-86.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-87.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-88.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-89.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-9.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-90.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-91.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-92.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-93.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-94.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-95.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-96.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-97.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-98.txt1
-rw-r--r--tests/benchmarks/many-small-files/small-file-99.txt1
-rwxr-xr-xtests/benchmarks/run-benchmarks.sh10
-rw-r--r--tests/integration_tests.rs67
-rw-r--r--tests/snapshots/output/full.snapshot.txt1
111 files changed, 302 insertions, 42 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97bc6e7b..ae734641 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Features
+- New style component `header-filesize` to show size of the displayed file in the header. See #1988 (@mdibaiee)
+
## Bugfixes
## Other
diff --git a/Cargo.lock b/Cargo.lock
index 4d8fecb1..4c17fd90 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -82,6 +82,7 @@ dependencies = [
"atty",
"bincode",
"bugreport",
+ "bytesize",
"clap",
"clircle",
"console",
@@ -170,6 +171,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f"
[[package]]
+name = "bytesize"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
+
+[[package]]
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 639e9d96..99a65642 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,6 +65,7 @@ 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 }
+bytesize = { version = "1.1.0" }
[dependencies.git2]
version = "0.13"
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index e0460f74..0a1a81cf 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -396,11 +396,19 @@ 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",
+ "header-filename",
+ "header-filesize",
+ "grid",
+ "rule",
+ "numbers",
+ "snip",
#[cfg(feature = "git")]
- "changes",
- ]
- .contains(style)
+ "changes",
+ ].contains(style)
});
if let Some(invalid) = invalid_vals.next() {
@@ -426,7 +434,9 @@ 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 \
+ * header: alias for 'header-filename'.\n \
+ * header-filename: show filenames before the content.\n \
+ * header-filesize: show file sizes before the content.\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 ffaca0ae..3c295822 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,4 +1,5 @@
use std::convert::TryFrom;
+use std::fs;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read};
use std::path::{Path, PathBuf};
@@ -87,6 +88,7 @@ impl<'a> InputKind<'a> {
#[derive(Clone, Default)]
pub(crate) struct InputMetadata {
pub(crate) user_provided_name: Option<PathBuf>,
+ pub(crate) size: Option<u64>,
}
pub struct Input<'a> {
@@ -130,9 +132,14 @@ impl<'a> Input<'a> {
fn _ordinary_file(path: &Path) -> Self {
let kind = InputKind::OrdinaryFile(path.to_path_buf());
+ let metadata = InputMetadata {
+ size: fs::metadata(path).map(|m| m.len()).ok(),
+ ..InputMetadata::default()
+ };
+
Input {
descr