$DEBUG to see output in stderr
parent
8fded3ccaf
commit
fa72770986
|
|
@ -18,6 +18,7 @@ pub struct Streams {
|
|||
pub struct Stream {
|
||||
pub engine: Engine,
|
||||
pub format: Option<String>,
|
||||
pub debug: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
@ -83,6 +84,7 @@ fn build_config_std() -> Config {
|
|||
return Config {
|
||||
streams: Streams{
|
||||
input: Stream {
|
||||
debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true",
|
||||
format: match env::var("INPUT_FORMAT") {
|
||||
Ok(x) => Some(x),
|
||||
Err(_) => None,
|
||||
|
|
@ -110,6 +112,7 @@ fn build_config_std() -> Config {
|
|||
},
|
||||
},
|
||||
output: Stream {
|
||||
debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true",
|
||||
format: match env::var("OUTPUT_FORMAT") {
|
||||
Ok(x) => Some(x),
|
||||
Err(_) => None,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue