aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorMroik <mroik@delayed.space>2025-11-27 05:45:19 +0100
committerMroik <mroik@delayed.space>2025-11-27 05:45:19 +0100
commitee1c9f86982af88713c063509a7c4fac1f2e7007 (patch)
treecd147e997b906deb634a97083763fd278e96fe02 /src/input.rs
parentdd18fb1169b3e56efad9e00c87db55a46e0f1083 (diff)
Rename module
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
new file mode 100644
index 0000000..7e0db3e
--- /dev/null
+++ b/src/input.rs
@@ -0,0 +1,41 @@
+use std::{error::Error, time::Duration};
+
+use crossterm::event::{KeyCode, KeyModifiers, poll, read};
+use tokio::sync::mpsc::Sender;
+
+use crate::app::TICK_RATE;
+
+#[derive(PartialEq)]
+pub enum Event {
+ Terminate,
+ KeyPress(char),
+ Backspace,
+ Render,
+ ForceRender,
+}
+
+// TODO
+// - [ ] Pause on focus lost
+// - [ ] Invalidate on paste
+pub async fn handle_input(sender: &Sender<Event>) -> Result<(), Box<dyn Error>> {
+ if poll(Duration::from_millis(TICK_RATE))? {
+ match read()? {
+ //crossterm::event::Event::FocusGained => todo!(),
+ //crossterm::event::Event::FocusLost => todo!(),
+ //crossterm::event::Event::Paste(_) => todo!(),
+ crossterm::event::Event::Resize(_, _) => sender.send(Event::ForceRender).await?,
+ crossterm::event::Event::Key(key_event) => {
+ match (key_event.code, key_event.modifiers) {
+ (KeyCode::Char('c'), KeyModifiers::CONTROL) => {
+ sender.send(Event::Terminate).await?
+ }
+ (KeyCode::Backspace, _) => sender.send(Event::Backspace).await?,
+ (KeyCode::Char(c), _) => sender.send(Event::KeyPress(c)).await?,
+ _ => (),
+ }
+ }
+ _ => (),
+ }
+ }
+ return Ok(());
+}
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj