mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 07:56:56 +02:00
term: add combined tui_io
This commit is contained in:
parent
53c9438f7d
commit
4e6c62a7f1
1 changed files with 17 additions and 2 deletions
19
src/term.rs
19
src/term.rs
|
|
@ -39,9 +39,8 @@ pub fn tui_run_main <T> (state: T) -> Usually<()> where
|
|||
Exit::run(|exit|{
|
||||
let state = Arc::new(RwLock::new(state));
|
||||
let scan = Duration::from_millis(100);
|
||||
let input = tui_input(exit.as_ref(), &state, scan)?;
|
||||
let frame = Duration::from_millis(10);
|
||||
let output = tui_output(exit.as_ref(), &state, frame, std::io::stdout())?;
|
||||
let (input, output) = tui_io(exit.as_ref(), &state, scan, frame, std::io::stdout())?;
|
||||
output.join();
|
||||
stdout().execute(LeaveAlternateScreen)?;
|
||||
CrosstermBackend::new(stdout()).show_cursor()?;
|
||||
|
|
@ -73,6 +72,22 @@ pub fn tui_setup_panic () {
|
|||
};
|
||||
}
|
||||
|
||||
/// Spawn the TUI input and output threadsl.
|
||||
pub fn tui_io <
|
||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static,
|
||||
W: Write + Send + Sync + 'static,
|
||||
> (
|
||||
exited: &Arc<AtomicBool>,
|
||||
state: &Arc<RwLock<T>>,
|
||||
poll: Duration,
|
||||
sleep: Duration,
|
||||
output: W,
|
||||
) -> Result<(Task, Task), Box<dyn Error>> {
|
||||
let keyboard = tui_input(exited, state, poll)?;
|
||||
let terminal = tui_output(exited, state, sleep, output)?;
|
||||
Ok((keyboard, terminal))
|
||||
}
|
||||
|
||||
/// Spawn the TUI input thread which reads keys from the terminal.
|
||||
pub fn tui_input <T: Apply<TuiEvent, Usually<()>> + Send + Sync + 'static> (
|
||||
exited: &Arc<AtomicBool>, state: &Arc<RwLock<T>>, poll: Duration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue