From 4e6c62a7f1edd9e173065afbb8e9cf897baa2ead Mon Sep 17 00:00:00 2001 From: facile pop culture reference Date: Mon, 29 Jun 2026 20:38:08 +0300 Subject: [PATCH] term: add combined tui_io --- src/term.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/term.rs b/src/term.rs index c2e836d..b5fa807 100644 --- a/src/term.rs +++ b/src/term.rs @@ -39,9 +39,8 @@ pub fn tui_run_main (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 + Apply> + Send + Sync + 'static, + W: Write + Send + Sync + 'static, +> ( + exited: &Arc, + state: &Arc>, + poll: Duration, + sleep: Duration, + output: W, +) -> Result<(Task, Task), Box> { + 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 > + Send + Sync + 'static> ( exited: &Arc, state: &Arc>, poll: Duration