poo
parent
5d776fd294
commit
36380004b5
|
|
@ -137,6 +137,15 @@ version = "0.1.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.0"
|
||||
|
|
@ -350,6 +359,15 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.2"
|
||||
|
|
@ -425,6 +443,16 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cty"
|
||||
version = "0.2.2"
|
||||
|
|
@ -477,6 +505,16 @@ dependencies = [
|
|||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
|
|
@ -790,10 +828,14 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.55"
|
||||
name = "generic-array"
|
||||
version = "0.14.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
|
||||
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
|
|
@ -960,6 +1002,20 @@ dependencies = [
|
|||
"svg_fmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "handlebars"
|
||||
version = "4.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "035ef95d03713f2c347a72547b7cd38cbc9af7cd51e6099fb62d586d4a6dee3a"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
|
|
@ -1673,6 +1729,50 @@ version = "2.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "pest"
|
||||
version = "2.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"ucd-trie",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_derive"
|
||||
version = "2.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a81186863f3d0a27340815be8f2078dd8050b14cd71913db9fbda795e5f707d7"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_generator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_generator"
|
||||
version = "2.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_meta"
|
||||
version = "2.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e3b284b1f13a20dc5ebc90aff59a51b8d7137c221131b52a7260c08cbc1cc80"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"pest",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.11.1"
|
||||
|
|
@ -1751,16 +1851,6 @@ version = "0.2.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "printf"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15343a566c054c72bdc3f3f138002a87e5320d7389c9713112c9b77e83539141"
|
||||
dependencies = [
|
||||
"gcc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
|
|
@ -1950,13 +2040,14 @@ name = "rusty-pipe"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gilrs",
|
||||
"handlebars",
|
||||
"hidapi",
|
||||
"iced",
|
||||
"iced_native",
|
||||
"printf",
|
||||
"rdkafka",
|
||||
"rusb",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
]
|
||||
|
||||
|
|
@ -2064,6 +2155,17 @@ dependencies = [
|
|||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
|
|
@ -2299,6 +2401,18 @@ dependencies = [
|
|||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-trie"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ edition = "2021"
|
|||
[dependencies]
|
||||
serde = { version = "1.0.156", features = ["derive"] }
|
||||
serde_yaml = "0.9.19"
|
||||
serde_json = "1"
|
||||
rdkafka = "0.29.0"
|
||||
rusb = "0.9.1"
|
||||
hidapi = "0.5.0"
|
||||
gilrs = "0.10.1"
|
||||
iced = "0.8.0"
|
||||
iced_native = "0.9.1"
|
||||
printf = "0.1.0"
|
||||
handlebars = "4"
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use crate::config::Stream;
|
|||
use hidapi::HidApi;
|
||||
use rusb::UsbContext;
|
||||
use gilrs::{Gilrs, Button, Event};
|
||||
use printf;
|
||||
use std::os::raw::c_void;
|
||||
use serde_json::json;
|
||||
use handlebars::Handlebars;
|
||||
|
||||
pub trait InputStream {
|
||||
fn get(&mut self) -> Vec<char>;
|
||||
|
|
@ -197,37 +197,39 @@ pub fn build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
|
|||
return build_formatted_output_stream(cfg, _build_output_stream(cfg))
|
||||
}
|
||||
|
||||
pub struct OutputStreamFormatted {
|
||||
format: Option<String>,
|
||||
pub struct OutputStreamFormatted<'a> {
|
||||
format: Option<Box<&'a dyn Fn(Vec<char>) -> Vec<char>>>,
|
||||
stream: Box<dyn OutputStream>,
|
||||
}
|
||||
|
||||
pub fn build_formatted_output_stream(cfg: &Stream, stream: Box<dyn OutputStream>) -> Box<dyn OutputStream> {
|
||||
return Box::new(OutputStreamFormatted{
|
||||
format: cfg.format.clone(),
|
||||
format: match cfg.format.clone() {
|
||||
Some(x) => {
|
||||
let x = x.clone();
|
||||
Some(Box::new(
|
||||
&|v: Vec<char>| {
|
||||
let mut reg = Handlebars::new();
|
||||
reg.register_template_string("x", x.clone());
|
||||
reg.render("x", &json!({"x": v})).unwrap().chars().collect()
|
||||
},
|
||||
))
|
||||
},
|
||||
None => None,
|
||||
},
|
||||
stream: stream,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO use https://crates.io/crates/handlebars instead
|
||||
impl OutputStream for OutputStreamFormatted {
|
||||
impl<'a> OutputStream for OutputStreamFormatted<'a> {
|
||||
fn put(&mut self, v: Vec<char>) {
|
||||
match self.format.as_ref() {
|
||||
Some(x) => self.stream.put(sprintf(x, v)),
|
||||
Some(x) => self.stream.put(x(v)),
|
||||
None => self.stream.put(v),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn sprintf(format: &String, arg: Vec<char>) -> Vec<char> {
|
||||
unsafe {
|
||||
return printf::printf(
|
||||
format.as_bytes().as_ptr() as *const i8,
|
||||
arg.iter().cloned().collect::<String>().as_bytes().as_ptr() as *mut c_void,
|
||||
).chars().collect();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn _build_output_stream(cfg: &Stream) -> Box<dyn OutputStream> {
|
||||
if cfg.engine.name.as_str() == "stdout" {
|
||||
return Box::new(OutputStreamStdout{});
|
||||
|
|
@ -266,8 +268,9 @@ mod test_output {
|
|||
engine.put("teehee".to_string().chars().collect());
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn test_sprintf() {
|
||||
fn test_output_stream_formatted() {
|
||||
assert_eq!(
|
||||
"hello world".to_string().chars().collect::<Vec<char>>(),
|
||||
sprintf(
|
||||
|
|
@ -276,6 +279,7 @@ mod test_output {
|
|||
),
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
pub struct OutputStreamUDP {
|
||||
|
|
|
|||
Loading…
Reference in New Issue