Skip to main content

phosphor_tui/
lib.rs

1//! Terminal UI frontend for Phosphor.
2
3pub mod actions;
4mod app;
5pub mod debug_log;
6pub mod session;
7mod splash;
8pub mod state;
9#[cfg(test)]
10mod test_harness;
11#[cfg(test)]
12mod test_clips;
13mod theme;
14mod ui;
15
16use anyhow::Result;
17use phosphor_core::EngineConfig;
18
19/// Run the TUI application.
20pub fn run(config: EngineConfig, enable_audio: bool, enable_midi: bool) -> Result<()> {
21    debug_log::init();
22    theme::load_preference();
23
24    // Install panic handler that logs to our debug file before crashing
25    let default_hook = std::panic::take_hook();
26    std::panic::set_hook(Box::new(move |info| {
27        let location = info.location().map(|l| format!("{}:{}:{}", l.file(), l.line(), l.column())).unwrap_or_default();
28        let msg = if let Some(s) = info.payload().downcast_ref::<&str>() {
29            s.to_string()
30        } else if let Some(s) = info.payload().downcast_ref::<String>() {
31            s.clone()
32        } else {
33            "unknown panic".to_string()
34        };
35        let bt = std::backtrace::Backtrace::force_capture();
36        debug_log::log("PANIC", &format!("{msg} at {location}"));
37        debug_log::log("PANIC", &format!("backtrace:\n{bt}"));
38        default_hook(info);
39    }));
40
41    let mut app = app::App::new_with_splash(config, enable_audio, enable_midi)?;
42    app.run()
43}