1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 03:12:25 +01:00

Merge branch 'master' of github.com:sharkdp/bat into string-input

This commit is contained in:
Ethan P
2020-05-15 13:22:24 -07:00
19 changed files with 68 additions and 20 deletions

View File

@@ -75,7 +75,7 @@ impl<'b> Controller<'b> {
}
};
for input in inputs.into_iter() {
for (index, input) in inputs.into_iter().enumerate() {
match input.open(io::stdin().lock()) {
Err(error) => {
print_error(&error, writer);
@@ -128,6 +128,7 @@ impl<'b> Controller<'b> {
&mut *printer,
writer,
&mut opened_input,
index != 0,
#[cfg(feature = "git")]
&line_changes,
);
@@ -148,10 +149,11 @@ impl<'b> Controller<'b> {
printer: &mut dyn Printer,
writer: &mut dyn Write,
input: &mut OpenedInput,
add_header_padding: bool,
#[cfg(feature = "git")] line_changes: &Option<LineChanges>,
) -> Result<()> {
if !input.reader.first_line.is_empty() || self.config.style_components.header() {
printer.print_header(writer, input)?;
printer.print_header(writer, input, add_header_padding)?;
}
if !input.reader.first_line.is_empty() {

View File

@@ -33,7 +33,12 @@ use crate::terminal::{as_terminal_escaped, to_ansi_color};
use crate::wrapping::WrappingMode;
pub(crate) trait Printer {
fn print_header(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
fn print_header(
&mut self,
handle: &mut dyn Write,
input: &OpenedInput,
add_header_padding: bool,
) -> Result<()>;
fn print_footer(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
@@ -56,7 +61,12 @@ impl SimplePrinter {
}
impl Printer for SimplePrinter {
fn print_header(&mut self, _handle: &mut dyn Write, _input: &OpenedInput) -> Result<()> {
fn print_header(
&mut self,
_handle: &mut dyn Write,
_input: &OpenedInput,
_add_header_padding: bool,
) -> Result<()> {
Ok(())
}
@@ -219,7 +229,12 @@ impl<'a> InteractivePrinter<'a> {
}
impl<'a> Printer for InteractivePrinter<'a> {
fn print_header(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()> {
fn print_header(
&mut self,
handle: &mut dyn Write,
input: &OpenedInput,
add_header_padding: bool,
) -> Result<()> {
if !self.config.style_components.header() {
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
writeln!(
@@ -248,6 +263,9 @@ impl<'a> Printer for InteractivePrinter<'a> {
.paint(if self.panel_width > 0 { "" } else { "" }),
)?;
} else {
if add_header_padding {
writeln!(handle)?;
}
write!(handle, "{}", " ".repeat(self.panel_width))?;
}