mirror of https://github.com/sayanarijit/xplr
Fix create mode, refactor readers, fix init focus
parent
c2bc8aee20
commit
c0ca596539
@ -0,0 +1,35 @@
|
|||||||
|
use crate::app::Task;
|
||||||
|
use crate::app::{ExternalMsg, InternalMsg, MsgIn};
|
||||||
|
use crate::input::Key;
|
||||||
|
use crossterm::event::{self, Event};
|
||||||
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
pub fn keep_reading(tx_msg_in: Sender<Task>, rx_event_reader: Receiver<bool>) {
|
||||||
|
thread::spawn(move || {
|
||||||
|
let mut is_paused = false;
|
||||||
|
loop {
|
||||||
|
if let Some(paused) = rx_event_reader.try_recv().ok() {
|
||||||
|
is_paused = paused;
|
||||||
|
};
|
||||||
|
|
||||||
|
if !is_paused {
|
||||||
|
if event::poll(std::time::Duration::from_millis(1)).unwrap() {
|
||||||
|
match event::read().unwrap() {
|
||||||
|
Event::Key(key) => {
|
||||||
|
let key = Key::from_event(key);
|
||||||
|
let msg = MsgIn::Internal(InternalMsg::HandleKey(key));
|
||||||
|
tx_msg_in.send(Task::new(0, msg, Some(key))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::Resize(_, _) => {
|
||||||
|
let msg = MsgIn::External(ExternalMsg::Refresh);
|
||||||
|
tx_msg_in.send(Task::new(0, msg, None)).unwrap();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
use crate::app::{ExternalMsg, MsgIn, Task};
|
||||||
|
use serde_yaml;
|
||||||
|
use std::fs;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub fn keep_reading(pipe: String, tx: Sender<Task>) {
|
||||||
|
thread::spawn(move || loop {
|
||||||
|
let in_str = fs::read_to_string(&pipe).unwrap_or_default();
|
||||||
|
|
||||||
|
if !in_str.is_empty() {
|
||||||
|
let msgs = in_str
|
||||||
|
.lines()
|
||||||
|
.filter_map(|s| serde_yaml::from_str::<ExternalMsg>(s.trim()).ok());
|
||||||
|
|
||||||
|
msgs.for_each(|msg| {
|
||||||
|
tx.send(Task::new(2, MsgIn::External(msg), None)).unwrap();
|
||||||
|
});
|
||||||
|
fs::write(&pipe, "").unwrap();
|
||||||
|
};
|
||||||
|
thread::sleep(Duration::from_millis(10));
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue