$DEBUG to see output in stderr
parent
8fded3ccaf
commit
fa72770986
|
|
@ -18,6 +18,7 @@ pub struct Streams {
|
||||||
pub struct Stream {
|
pub struct Stream {
|
||||||
pub engine: Engine,
|
pub engine: Engine,
|
||||||
pub format: Option<String>,
|
pub format: Option<String>,
|
||||||
|
pub debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
@ -83,6 +84,7 @@ fn build_config_std() -> Config {
|
||||||
return Config {
|
return Config {
|
||||||
streams: Streams{
|
streams: Streams{
|
||||||
input: Stream {
|
input: Stream {
|
||||||
|
debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true",
|
||||||
format: match env::var("INPUT_FORMAT") {
|
format: match env::var("INPUT_FORMAT") {
|
||||||
Ok(x) => Some(x),
|
Ok(x) => Some(x),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
|
|
@ -110,6 +112,7 @@ fn build_config_std() -> Config {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
output: Stream {
|
output: Stream {
|
||||||
|
debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true",
|
||||||
format: match env::var("OUTPUT_FORMAT") {
|
format: match env::var("OUTPUT_FORMAT") {
|
||||||
Ok(x) => Some(x),
|
Ok(x) => Some(x),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
|
|
|
||||||
|
|
@ -201,21 +201,27 @@ pub fn build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
|
||||||
pub struct OutputStreamFormatted {
|
pub struct OutputStreamFormatted {
|
||||||
format: Option<String>,
|
format: Option<String>,
|
||||||
stream: Box<dyn OutputStream>,
|
stream: Box<dyn OutputStream>,
|
||||||
|
debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_formatted_output_stream(cfg: &Stream, stream: Box<dyn OutputStream>) -> Box<dyn OutputStream> {
|
pub fn build_formatted_output_stream(cfg: &Stream, stream: Box<dyn OutputStream>) -> Box<dyn OutputStream> {
|
||||||
return Box::new(OutputStreamFormatted{
|
return Box::new(OutputStreamFormatted{
|
||||||
format: cfg.format.clone(),
|
format: cfg.format.clone(),
|
||||||
|
debug: cfg.debug,
|
||||||
stream: stream,
|
stream: stream,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputStream for OutputStreamFormatted {
|
impl OutputStream for OutputStreamFormatted {
|
||||||
fn put(&mut self, v: Vec<char>) {
|
fn put(&mut self, v: Vec<char>) {
|
||||||
match self.format.as_ref() {
|
let v2 = match self.format.as_ref() {
|
||||||
Some(x) => self.stream.put(sprintf(x, v)),
|
Some(x) => sprintf(x, v),
|
||||||
None => self.stream.put(v),
|
None => v,
|
||||||
};
|
};
|
||||||
|
if self.debug {
|
||||||
|
eprintln!("output: {}", v2.iter().collect::<String>());
|
||||||
|
}
|
||||||
|
self.stream.put(v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue