summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Peter <sharkdp@users.noreply.github.com>2020-07-02 08:21:50 +0200
committerGitHub <noreply@github.com>2020-07-02 08:21:50 +0200
commit3a62e3d18835dce57294e5cec48e9d878351629b (patch)
treed56e763a300f81a4a48642a05b2c38dd35dd22f0 /src
parent963d9ee584dc3fbc19641a39a3fc2024a242384a (diff)
parent3c5ce9f86cdb2a5e915d78770137a7d55a9c1dae (diff)
Merge pull request #1066 from gsomix/feature/1061-show-all-redirected
Enable non-printable characters for redirected output
Diffstat (limited to 'src')
-rw-r--r--src/controller.rs2
-rw-r--r--src/printer.rs22
2 files changed, 17 insertions, 7 deletions
diff --git a/src/controller.rs b/src/controller.rs
index e11080f5..3fe44a72 100644
--- a/src/controller.rs
+++ b/src/controller.rs
@@ -113,7 +113,7 @@ impl<'b> Controller<'b> {
};
let mut printer: Box<dyn Printer> = if self.config.loop_through {
- Box::new(SimplePrinter::new())
+ Box::new(SimplePrinter::new(&self.config))
} else {
Box::new(InteractivePrinter::new(
&self.config,
diff --git a/src/printer.rs b/src/printer.rs
index addc7972..7e369a6e 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -52,15 +52,17 @@ pub(crate) trait Printer {
) -> Result<()>;
}
-pub struct SimplePrinter;
+pub struct SimplePrinter<'a> {
+ config: &'a Config<'a>
+}
-impl SimplePrinter {
- pub fn new() -> Self {
- SimplePrinter {}
+impl<'a> SimplePrinter<'a> {
+ pub fn new(config: &'a Config) -> Self {
+ SimplePrinter { config }
}
}
-impl Printer for SimplePrinter {
+impl<'a> Printer for SimplePrinter<'a> {
fn print_header(
&mut self,
_handle: &mut dyn Write,
@@ -86,7 +88,15 @@ impl Printer for SimplePrinter {
line_buffer: &[u8],
) -> Result<()> {
if !out_of_range {
- handle.write_all(line_buffer)?;
+ if self.config.show_nonprintable {
+ let line = replace_nonprintable(line_buffer, self.config.tab_width);
+ write!(handle, "{}", line)?;
+ if line_buffer.last() == Some(&b'\n') {
+ writeln!(handle)?;
+ }
+ } else {
+ handle.write_all(line_buffer)?
+ };
}
Ok(())
}