use std::sync::Arc;
use platform_tui::{OscClipboard, TuiPlatform, TuiPlatformConfig};
use renderer_tui::{CellMetrics, CellSize, ColorDepth, TuiConfig, TuiRendererFactory};
use services_core::{AppPathsProvider, SystemPaths};
use crate::app::App;
use crate::app_config::AppConfig;
#[derive(Clone, Debug)]
pub struct TuiOptions {
pub cell: CellSize,
pub depth: Option<ColorDepth>,
pub mouse: bool,
pub quit_on_ctrl_c: bool,
}
impl Default for TuiOptions {
fn default() -> Self {
Self {
cell: CellSize::default(),
depth: None,
mouse: true,
quit_on_ctrl_c: true,
}
}
}
pub fn run_tui_app_with_name<A: App>(
config: AppConfig,
options: TuiOptions,
app: A,
app_name: &str,
) {
renderer_core::set_text_metrics(CellMetrics::new(options.cell));
geometry_core::set_layout_grid(geometry_core::LayoutGrid::new(
options.cell.width,
options.cell.height,
));
ui_tree::set_smooth_wheel(false);
services_core::set_clipboard(Arc::new(OscClipboard::new()));
let paths: Arc<dyn AppPathsProvider> = Arc::new(SystemPaths);
let platform = TuiPlatform::new(TuiPlatformConfig {
cell_width: options.cell.width,
cell_height: options.cell.height,
mouse: options.mouse,
quit_on_ctrl_c: options.quit_on_ctrl_c,
});
let factory = TuiRendererFactory::new(TuiConfig {
cell: options.cell,
depth: options.depth.unwrap_or_else(ColorDepth::detect),
..TuiConfig::default()
});
if let Err(e) = super::run_with_platform_and_renderer::<_, _, A, ()>(
platform, factory, config, paths, app, app_name,
) {
eprintln!("telar: {e}");
std::process::exit(1);
}
}