move gui sending to output_stream into func

master
bel 2023-03-24 23:15:40 -06:00
parent b710080497
commit de2b4f4da6
1 changed files with 45 additions and 44 deletions

View File

@ -4,6 +4,8 @@ use iced::keyboard;
use iced::subscription;
use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command};
use iced_futures::backend::native::async_std::time::every;
use handlebars::Handlebars;
use std::time::{SystemTime, UNIX_EPOCH};
use crate::stream::OutputStream;
use crate::config::GUI;
@ -95,6 +97,48 @@ impl Main {
_ => 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 => {},
};
}
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() {
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();
}
}
impl Application for Main {
@ -135,50 +179,7 @@ impl Application for Main {
fn update(&mut self, msg: Message) -> Command<Message> {
match msg.clone() {
Message::Tick => {
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 => {},
};
}
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();
self.exchange();
},
Message::EventOccurred(event) if self.configuring.is_some() => {
match event {