if not CONFIG_PATH then more env
parent
96ce4d1855
commit
6ce7cd0b46
|
|
@ -68,21 +68,33 @@ fn build_config_std() -> Config {
|
|||
return Config {
|
||||
streams: Streams{
|
||||
input: Stream {
|
||||
format: None,
|
||||
format: match env::var("INPUT_FORMAT") {
|
||||
Ok(x) => Some(x),
|
||||
Err(_) => None,
|
||||
},
|
||||
engine: Engine{
|
||||
name: String::from("gui"),
|
||||
kafka: None,
|
||||
device: None,
|
||||
udp: None,
|
||||
udp: Some(UDP{
|
||||
host: Some(env::var("INPUT_UDP_HOST").unwrap_or(String::from("localhost"))),
|
||||
port: env::var("INPUT_UDP_PORT").unwrap_or(String::from("17070")).parse().unwrap(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
output: Stream {
|
||||
format: Some(String::from("%s")),
|
||||
format: match env::var("OUTPUT_FORMAT") {
|
||||
Ok(x) => Some(x),
|
||||
Err(_) => None,
|
||||
},
|
||||
engine: Engine{
|
||||
name: String::from("stdout"),
|
||||
name: env::var("OUTPUT_NAME").unwrap_or(String::from("stdout")),
|
||||
kafka: None,
|
||||
device: None,
|
||||
udp: None,
|
||||
udp: Some(UDP{
|
||||
host: Some(env::var("OUTPUT_UDP_HOST").unwrap_or(String::from("localhost"))),
|
||||
port: env::var("OUTPUT_UDP_PORT").unwrap_or(String::from("17070")).parse().unwrap(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Comma
|
|||
|
||||
use crate::stream::OutputStream;
|
||||
|
||||
pub fn main(outputStream: Box<dyn OutputStream>) -> iced::Result {
|
||||
pub fn main(output_stream: Box<dyn OutputStream>) -> iced::Result {
|
||||
let def: iced::Settings<()> = Settings::default();
|
||||
let settings = Settings{
|
||||
flags: Flags {
|
||||
outputStream: outputStream,
|
||||
output_stream: output_stream,
|
||||
},
|
||||
antialiasing: def.antialiasing,
|
||||
default_font: def.default_font,
|
||||
|
|
@ -33,7 +33,7 @@ struct Main {
|
|||
}
|
||||
|
||||
struct Flags {
|
||||
outputStream: Box<dyn OutputStream>,
|
||||
output_stream: Box<dyn OutputStream>,
|
||||
}
|
||||
|
||||
struct Inputs {
|
||||
|
|
@ -153,7 +153,7 @@ impl Application for Main {
|
|||
_ => String::from(""),
|
||||
};
|
||||
if s.len() > 0 {
|
||||
self.flags.outputStream.put(s.chars().collect());
|
||||
self.flags.output_stream.put(s.chars().collect());
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue