if not CONFIG_PATH then more env
This commit is contained in:
@@ -4,6 +4,7 @@ use hidapi::HidApi;
|
||||
use rusb::UsbContext;
|
||||
use gilrs::{Gilrs, Button, Event};
|
||||
use serde_json::json;
|
||||
use handlebars::Handlebars;
|
||||
|
||||
pub trait InputStream {
|
||||
fn get(&mut self) -> Vec<char>;
|
||||
@@ -197,18 +198,17 @@ pub fn build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
|
||||
}
|
||||
|
||||
pub struct OutputStreamFormatted {
|
||||
format: Box<dyn Fn(Vec<char>) -> Vec<char>>,
|
||||
format: Option<String>,
|
||||
stream: Box<dyn OutputStream>,
|
||||
}
|
||||
|
||||
pub fn build_formatted_output_stream(cfg: &Stream, stream: Box<dyn OutputStream>) -> Box<dyn OutputStream> {
|
||||
return Box::new(OutputStreamFormatted{
|
||||
format: Box::new(|v: Vec<char>| reg.render("x", &json!()).unwrap()),
|
||||
format: cfg.format.clone(),
|
||||
stream: stream,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO use https://crates.io/crates/handlebars instead
|
||||
impl OutputStream for OutputStreamFormatted {
|
||||
fn put(&mut self, v: Vec<char>) {
|
||||
match self.format.as_ref() {
|
||||
@@ -218,6 +218,13 @@ impl OutputStream for OutputStreamFormatted {
|
||||
}
|
||||
}
|
||||
|
||||
fn sprintf(x: &String, v: Vec<char>) -> Vec<char> {
|
||||
let mut reg = Handlebars::new();
|
||||
return reg.render_template(x, &json!({
|
||||
"VALUE": v.iter().collect::<String>(),
|
||||
})).unwrap().chars().collect();
|
||||
}
|
||||
|
||||
pub fn _build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
|
||||
if cfg.engine.name.as_str() == "stdout" {
|
||||
return Box::new(OutputStreamStdout{});
|
||||
@@ -256,18 +263,16 @@ mod test_output {
|
||||
engine.put("teehee".to_string().chars().collect());
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn test_output_stream_formatted() {
|
||||
assert_eq!(
|
||||
"hello world".to_string().chars().collect::<Vec<char>>(),
|
||||
sprintf(
|
||||
&String::from("hello %s"),
|
||||
&String::from("hello {{ VALUE }}"),
|
||||
String::from("world").chars().collect(),
|
||||
),
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
pub struct OutputStreamUDP {
|
||||
|
||||
Reference in New Issue
Block a user