mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
This commit is contained in:
parent
39d3dacf1f
commit
cf67185ffd
2 changed files with 12 additions and 10 deletions
|
|
@ -252,10 +252,11 @@ macro_rules! eval_xy (
|
|||
#[cfg(feature = "exit")] pub use self::exit::*;
|
||||
#[cfg(feature = "exit")] mod exit {
|
||||
use crate::*;
|
||||
use std::sync::{Arc, atomic::AtomicBool};
|
||||
use std::sync::{Arc, atomic::{AtomicBool, Ordering::Relaxed}};
|
||||
use crossterm::event::*;
|
||||
|
||||
#[derive(Clone)] pub struct Exit(Arc<AtomicBool>);
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub struct Exit(Arc<AtomicBool>);
|
||||
|
||||
impl Exit {
|
||||
pub fn run <T> (run: impl FnOnce(Self)->Usually<T>) -> Usually<T> {
|
||||
|
|
@ -269,6 +270,9 @@ macro_rules! eval_xy (
|
|||
state: KeyEventState::NONE
|
||||
}))
|
||||
}
|
||||
pub fn exit (&self) {
|
||||
self.0.store(true, Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Arc<AtomicBool>> for Exit {
|
||||
|
|
|
|||
|
|
@ -145,16 +145,14 @@ impl Tui {
|
|||
panic(info);
|
||||
}));
|
||||
}
|
||||
pub fn run_main <T> (state: Arc<RwLock<T>>) -> Usually<()> where
|
||||
pub fn run_main <T> (exit: Exit, state: Arc<RwLock<T>>) -> Usually<()> where
|
||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
||||
{
|
||||
Exit::run(|exit|{
|
||||
let scan = Duration::from_millis(100);
|
||||
let frame = Duration::from_millis(10);
|
||||
let (_input, output) = Tui::io(exit.as_ref(), &state, scan, frame, std::io::stdout())?;
|
||||
let _ = output.join();
|
||||
Tui::teardown(&mut stdout())
|
||||
})
|
||||
}
|
||||
/// Spawn the TUI input and output threadsl.
|
||||
pub fn io <
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue