struggling with printing contexts, what a mess

This commit is contained in:
Andrew Gallant
2016-08-31 20:02:59 -04:00
parent 79f62012d7
commit 5aa3b9bc58
2 changed files with 323 additions and 32 deletions

View File

@@ -58,6 +58,24 @@ impl<W: io::Write> Printer<W> {
self.write(b"\n");
}
pub fn context<P: AsRef<Path>>(
&mut self,
path: P,
buf: &[u8],
start: usize,
end: usize,
line_number: Option<u64>,
) {
self.write(path.as_ref().to_string_lossy().as_bytes());
self.write(b"-");
if let Some(line_number) = line_number {
self.write(line_number.to_string().as_bytes());
self.write(b"-");
}
self.write(&buf[start..end]);
self.write(b"\n");
}
pub fn binary_matched<P: AsRef<Path>>(&mut self, path: P) {
wln!(&mut self.wtr, "binary file {} matches", path.as_ref().display());
}