$DEBUG to see output in stderr

This commit is contained in:
Bel LaPointe
2023-03-23 16:53:01 -06:00
parent 8fded3ccaf
commit fa72770986
2 changed files with 12 additions and 3 deletions

View File

@@ -201,21 +201,27 @@ pub fn build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
pub struct OutputStreamFormatted {
format: Option<String>,
stream: Box<dyn OutputStream>,
debug: bool,
}
pub fn build_formatted_output_stream(cfg: &Stream, stream: Box<dyn OutputStream>) -> Box<dyn OutputStream> {
return Box::new(OutputStreamFormatted{
format: cfg.format.clone(),
debug: cfg.debug,
stream: stream,
});
}
impl OutputStream for OutputStreamFormatted {
fn put(&mut self, v: Vec<char>) {
match self.format.as_ref() {
Some(x) => self.stream.put(sprintf(x, v)),
None => self.stream.put(v),
let v2 = match self.format.as_ref() {
Some(x) => sprintf(x, v),
None => v,
};
if self.debug {
eprintln!("output: {}", v2.iter().collect::<String>());
}
self.stream.put(v2);
}
}