mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 10:11:07 +00:00
Add squeeze functionality to SimplePrinter
This commit is contained in:
parent
13204c46e2
commit
6c2ce63101
@ -101,11 +101,15 @@ pub(crate) trait Printer {
|
|||||||
|
|
||||||
pub struct SimplePrinter<'a> {
|
pub struct SimplePrinter<'a> {
|
||||||
config: &'a Config<'a>,
|
config: &'a Config<'a>,
|
||||||
|
consecutive_empty_lines: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SimplePrinter<'a> {
|
impl<'a> SimplePrinter<'a> {
|
||||||
pub fn new(config: &'a Config) -> Self {
|
pub fn new(config: &'a Config) -> Self {
|
||||||
SimplePrinter { config }
|
SimplePrinter {
|
||||||
|
config,
|
||||||
|
consecutive_empty_lines: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +138,21 @@ impl<'a> Printer for SimplePrinter<'a> {
|
|||||||
_line_number: usize,
|
_line_number: usize,
|
||||||
line_buffer: &[u8],
|
line_buffer: &[u8],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
// Skip squeezed lines.
|
||||||
|
if let Some(squeeze_limit) = self.config.squeeze_lines {
|
||||||
|
if String::from_utf8_lossy(line_buffer)
|
||||||
|
.trim_end_matches(|c| c == '\r' || c == '\n')
|
||||||
|
.is_empty()
|
||||||
|
{
|
||||||
|
self.consecutive_empty_lines += 1;
|
||||||
|
if self.consecutive_empty_lines > squeeze_limit {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.consecutive_empty_lines = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !out_of_range {
|
if !out_of_range {
|
||||||
if self.config.show_nonprintable {
|
if self.config.show_nonprintable {
|
||||||
let line = replace_nonprintable(
|
let line = replace_nonprintable(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user