Add support for reading from stdin, closes #2

This commit is contained in:
sharkdp authored and David Peter committed 2018-05-07 23:27:38 +02:00
1 parent da92154163
commit 7e2e0c82ac
2 files changed
+52 -21

No files matched your search

+14 -4
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(())
}