mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-21 23:33:26 +01:00
Add --squeeze-limit to specify max number of consecutive empty lines
Co-authored-by: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com>
This commit is contained in:
parent
0c7e5299bf
commit
0e4e10edb6
@ -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
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -395,6 +395,13 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.help("Squeeze consecutive empty lines.")
|
||||
.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")
|
||||
|
@ -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"))]
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user