pub mod app;
pub mod chart_app;
pub mod effects;
pub mod event;
pub mod filtered_log;
pub(crate) mod hand_stats;
pub mod hand_store;
mod projection;
pub mod screens;
pub mod state;
pub mod terminal;
pub mod theme;
pub mod widgets;
use clap::Args;
pub async fn run_blocking_tui_loop<L>(
tui_loop: L,
work_handle: tokio::task::JoinHandle<()>,
on_tui_exit: impl FnOnce(),
) -> std::io::Result<()>
where
L: FnOnce() -> std::io::Result<()> + Send + 'static,
{
let tui_handle = tokio::task::spawn_blocking(tui_loop);
let tui_result = tui_handle.await;
on_tui_exit();
let _ = work_handle.await;
match tui_result {
Ok(result) => result,
Err(join_err) => Err(std::io::Error::other(join_err)),
}
}
#[derive(Args, Debug, Clone)]
pub struct TuiFlags {
#[arg(long = "tui")]
pub force_tui: bool,
#[arg(long = "no-tui")]
pub no_tui: bool,
}
impl TuiFlags {
pub fn should_use_tui(&self) -> bool {
let env_no_tui = std::env::var("RSP_NO_TUI").is_ok();
let is_tty = std::io::IsTerminal::is_terminal(&std::io::stdout());
resolve_tui(self.no_tui, self.force_tui, env_no_tui, is_tty)
}
}
fn resolve_tui(no_tui: bool, force_tui: bool, env_no_tui: bool, is_tty: bool) -> bool {
if no_tui {
return false;
}
if force_tui {
return true;
}
if env_no_tui {
return false;
}
is_tty
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_no_tui_flag_overrides_all() {
assert!(!resolve_tui(true, true, false, true));
}
#[test]
fn test_force_tui_flag() {
assert!(resolve_tui(false, true, false, false));
}
#[test]
fn test_no_tui_flag() {
assert!(!resolve_tui(true, false, false, true));
}
#[test]
fn test_env_var_disables_tui() {
assert!(!resolve_tui(false, false, true, true));
}
#[test]
fn test_tty_auto_detect() {
assert!(resolve_tui(false, false, false, true));
assert!(!resolve_tui(false, false, false, false));
}
}