summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan P <eth-p+git@hidden.email>2020-12-16 18:23:14 -0800
committereinfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com>2024-02-24 13:51:06 +0100
commit0e4e10edb6663b9ee73c850b9679b08929501c2f (patch)
treed595fcc15eaae8466555f6bc9643655e39778850
parent0c7e5299bf05d24c22dbff85964acec26ea3edf4 (diff)
Add --squeeze-limit to specify max number of consecutive empty lines
Co-authored-by: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com>
-rw-r--r--src/bin/bat/app.rs9
-rw-r--r--src/bin/bat/clap_app.rs7
-rw-r--r--src/config.rs2
-rw-r--r--src/pretty_printer.rs3
-rw-r--r--src/printer.rs4
5 files changed, 18 insertions, 7 deletions
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index 58f683cd..f462ce8d 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -291,9 +291,14 @@ impl App {
use_lessopen: self.matches.get_flag("lessopen"),
set_terminal_title: self.matches.get_flag("set-terminal-title"),
squeeze_lines: if self.matches.get_flag("squeeze") {
- 1
+ Some(
+ self.matches
+ .get_one::<usize>("squeeze-limit")
+ .map(|limit| limit.to_owned())
+ .unwrap_or(1),
+ )
} else {
- 0
+ None
},
})
}
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index 4bcee8d6..0c28ce7d 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -396,6 +396,13 @@ pub fn build_app(interactive_output: bool) -> Command {
.long_help("Squeeze consecutive empty lines into a single empty line.")
)
.arg(
+ Arg::new("squeeze-limit")
+ .long("squeeze-limit")
+ .value_parser(|s: &str| s.parse::<usize>().map_err(|_| "Requires a non-negative number".to_owned()))
+ .help("The maximum number of consecutive empty lines.")
+ .long_help("Set the maximum number of consecutive empty lines to be printed.")
+ )
+ .arg(
Arg::new("style")
.long("style")
.value_name("components")
diff --git a/src/config.rs b/src/config.rs
index ee0d5bc1..0298bb2a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -99,7 +99,7 @@ pub struct Config<'a> {
pub set_terminal_title: bool,
/// The maximum number of consecutive empty lines to display
- pub squeeze_lines: usize,
+ pub squeeze_lines: Option<usize>,
}
#[cfg(all(feature = "minimal-application", feature = "paging"))]
diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
index 614f0c91..c6203aa9 100644
--- a/src/pretty_printer.rs
+++ b/src/pretty_printer.rs
@@ -231,8 +231,7 @@ impl<'a> PrettyPrinter<'a> {
}
/// Specify the maximum number of consecutive empty lines to print.
- /// If set to `0`, all empty lines will be shown.
- pub fn squeeze_empty_lines(&mut self, maximum: usize) -> &mut Self {
+ pub fn squeeze_empty_lines(&mut self, maximum: Option<usize>) -> &mut Self {
self.config.squeeze_lines = maximum;
self
}
diff --git a/src/printer.rs b/src/printer.rs
index 636c0800..343f4486 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -580,10 +580,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
}
// Skip squeezed lines.
- if self.config.squeeze_lines > 0 {
+ if let Some(squeeze_limit) = self.config.squeeze_lines {
if line.trim_end_matches(|c| c == '\r' || c == '\n').is_empty() {
self.consecutive_empty_lines += 1;
- if self.consecutive_empty_lines > self.config.squeeze_lines {
+ if self.consecutive_empty_lines > squeeze_limit {
return Ok(());
}
} else {