1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-15 17:52:24 +01:00

Add support for reading from stdin, closes #2

This commit is contained in:
sharkdp
2018-05-07 19:59:40 +02:00
committed by David Peter
parent da92154163
commit 7e2e0c82ac
2 changed files with 52 additions and 21 deletions

View File

@@ -36,7 +36,7 @@ impl<'a> Printer<'a> {
}
}
pub fn print_header(&mut self, filename: &str) -> Result<()> {
pub fn print_header(&mut self, filename: Option<&str>) -> Result<()> {
match self.options.style {
OptionsStyle::Full => {}
_ => return Ok(()),
@@ -44,14 +44,22 @@ impl<'a> Printer<'a> {
self.print_horizontal_line('┬')?;
writeln!(
write!(
self.handle,
"{}{} File {}",
"{}{} ",
" ".repeat(PANEL_WIDTH),
self.colors.grid.paint(""),
self.colors.filename.paint(filename)
)?;
match filename {
None => {
writeln!(self.handle, "STDIN",)?;
}
Some(filename) => {
writeln!(self.handle, "File {}", self.colors.filename.paint(filename))?;
}
}
self.print_horizontal_line('┼')
}
@@ -89,6 +97,8 @@ impl<'a> Printer<'a> {
.join(" ")
)?;
self.handle.flush()?;
Ok(())
}