allow exiting via flag
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
facile pop culture reference 2026-08-06 10:18:35 +03:00
parent 39d3dacf1f
commit cf67185ffd
2 changed files with 12 additions and 10 deletions

View file

@ -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 {

View file

@ -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())
})
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 <