Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
357d35f787 | ||
|
|
de2b4f4da6 | ||
|
|
b710080497 | ||
|
|
e611e56d72 | ||
|
|
3ad12fcd29 |
@@ -39,6 +39,7 @@ pub struct GUI {
|
|||||||
pub buttons: Buttons,
|
pub buttons: Buttons,
|
||||||
pub press: PreSufFix,
|
pub press: PreSufFix,
|
||||||
pub release: PreSufFix,
|
pub release: PreSufFix,
|
||||||
|
pub format: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -125,9 +126,16 @@ fn build_config_std() -> Config {
|
|||||||
suffix: env::var("INPUT_GUI_PRESS_SUFFIX").unwrap_or(String::from("")),
|
suffix: env::var("INPUT_GUI_PRESS_SUFFIX").unwrap_or(String::from("")),
|
||||||
},
|
},
|
||||||
release: PreSufFix{
|
release: PreSufFix{
|
||||||
prefix: env::var("INPUT_GUI_RELEASE_PREFIX").unwrap_or(String::from("!")),
|
prefix: env::var("INPUT_GUI_RELEASE_PREFIX").unwrap_or(String::from("")),
|
||||||
suffix: env::var("INPUT_GUI_RELEASE_SUFFIX").unwrap_or(String::from("")),
|
suffix: env::var("INPUT_GUI_RELEASE_SUFFIX").unwrap_or(String::from("")),
|
||||||
},
|
},
|
||||||
|
format: match env::var("INPUT_GUI_FORMAT") {
|
||||||
|
Ok(x) => Some(x),
|
||||||
|
Err(_) => match env::var("INPUT_GUI_FORMAT_V01").unwrap_or(String::from("false")) == String::from("true") {
|
||||||
|
true => Some(String::from("{\"T\":{{ms}},\"U\":\"{{user}}\",\"Y\":\"{{pressed}}\",\"N\":\"{{released}}\"}")),
|
||||||
|
false => None,
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
device: None,
|
device: None,
|
||||||
udp: Some(UDP{
|
udp: Some(UDP{
|
||||||
|
|||||||
111
src/gui.rs
111
src/gui.rs
@@ -4,6 +4,9 @@ use iced::keyboard;
|
|||||||
use iced::subscription;
|
use iced::subscription;
|
||||||
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
|
||||||
use iced_futures::backend::native::async_std::time::every;
|
use iced_futures::backend::native::async_std::time::every;
|
||||||
|
use handlebars::Handlebars;
|
||||||
|
use serde_json::json;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use crate::stream::OutputStream;
|
use crate::stream::OutputStream;
|
||||||
use crate::config::GUI;
|
use crate::config::GUI;
|
||||||
@@ -95,6 +98,69 @@ impl Main {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exchange(&mut self) {
|
||||||
|
let mut s = vec![];
|
||||||
|
for key_code in self.keys_newly_down.iter() {
|
||||||
|
match self.key_code_to_string(key_code) {
|
||||||
|
Some(x) => {
|
||||||
|
for c in self.flags.cfg.press.prefix.chars() {
|
||||||
|
s.push(c);
|
||||||
|
}
|
||||||
|
for c in x.chars() {
|
||||||
|
s.push(c);
|
||||||
|
}
|
||||||
|
for c in self.flags.cfg.press.suffix.chars() {
|
||||||
|
s.push(c);
|
||||||
|
}
|
||||||
|
self.keys_already_down.push(*key_code);
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let mut t = vec![];
|
||||||
|
self.keys_newly_down.clear();
|
||||||
|
for key_code in self.keys_up.iter() {
|
||||||
|
match self.key_code_to_string(key_code) {
|
||||||
|
Some(x) => {
|
||||||
|
for c in x.chars() {
|
||||||
|
for c in self.flags.cfg.release.prefix.chars() {
|
||||||
|
t.push(c);
|
||||||
|
}
|
||||||
|
t.push(c);
|
||||||
|
for c in self.flags.cfg.release.suffix.chars() {
|
||||||
|
t.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if t.len() + s.len() > 0 {
|
||||||
|
self.flags.output_stream.put(self.sprintf(s, t));
|
||||||
|
}
|
||||||
|
self.keys_up.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sprintf(&self, pressed: Vec<char>, released: Vec<char>) -> Vec<char> {
|
||||||
|
match self.flags.cfg.format.clone() {
|
||||||
|
Some(x) => {
|
||||||
|
let reg = Handlebars::new();
|
||||||
|
return reg.render_template(&x, &json!({
|
||||||
|
"pressed": pressed.iter().collect::<String>(),
|
||||||
|
"released": released.iter().collect::<String>(),
|
||||||
|
"ms": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
|
||||||
|
"user": String::from(""),
|
||||||
|
})).unwrap().chars().collect();
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let mut combo = vec![];
|
||||||
|
combo.extend(pressed);
|
||||||
|
combo.extend(released);
|
||||||
|
return combo;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Main {
|
impl Application for Main {
|
||||||
@@ -135,50 +201,7 @@ impl Application for Main {
|
|||||||
fn update(&mut self, msg: Message) -> Command<Message> {
|
fn update(&mut self, msg: Message) -> Command<Message> {
|
||||||
match msg.clone() {
|
match msg.clone() {
|
||||||
Message::Tick => {
|
Message::Tick => {
|
||||||
let mut s = vec![];
|
self.exchange();
|
||||||
for key_code in self.keys_newly_down.iter() {
|
|
||||||
match self.key_code_to_string(key_code) {
|
|
||||||
Some(x) => {
|
|
||||||
for c in self.flags.cfg.press.prefix.chars() {
|
|
||||||
s.push(c);
|
|
||||||
}
|
|
||||||
for c in x.chars() {
|
|
||||||
s.push(c);
|
|
||||||
}
|
|
||||||
for c in self.flags.cfg.press.suffix.chars() {
|
|
||||||
s.push(c);
|
|
||||||
}
|
|
||||||
self.keys_already_down.push(*key_code);
|
|
||||||
},
|
|
||||||
None => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if s.len() > 0 {
|
|
||||||
self.flags.output_stream.put(s);
|
|
||||||
}
|
|
||||||
self.keys_newly_down.clear();
|
|
||||||
|
|
||||||
let mut s = vec![];
|
|
||||||
for key_code in self.keys_up.iter() {
|
|
||||||
match self.key_code_to_string(key_code) {
|
|
||||||
Some(x) => {
|
|
||||||
for c in x.chars() {
|
|
||||||
for c in self.flags.cfg.release.prefix.chars() {
|
|
||||||
s.push(c);
|
|
||||||
}
|
|
||||||
s.push(c);
|
|
||||||
for c in self.flags.cfg.release.suffix.chars() {
|
|
||||||
s.push(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if s.len() > 0 {
|
|
||||||
self.flags.output_stream.put(s);
|
|
||||||
}
|
|
||||||
self.keys_up.clear();
|
|
||||||
},
|
},
|
||||||
Message::EventOccurred(event) if self.configuring.is_some() => {
|
Message::EventOccurred(event) if self.configuring.is_some() => {
|
||||||
match event {
|
match event {
|
||||||
|
|||||||
Reference in New Issue
Block a user