Skip to main content

sonos_cli/tui/
mod.rs

1//! Interactive TUI for controlling Sonos speakers.
2//!
3//! Launched when `sonos` is run without arguments in a terminal.
4
5mod app;
6mod event;
7mod handlers;
8pub mod hooks;
9pub mod image_loader;
10mod screens;
11mod theme;
12mod ui;
13mod widgets;
14
15pub use app::App;
16
17use crate::config::Config;
18use anyhow::Result;
19use ratatui_image::picker::Picker;
20
21/// Launch the interactive TUI. Blocks until the user quits.
22pub fn run(config: Config) -> Result<()> {
23    // Detect terminal image protocol BEFORE entering raw mode.
24    // from_query_stdio() sends escape sequences to discover font size and
25    // graphics protocol support — must happen before ratatui::init().
26    let picker = if config.album_art_mode.is_off() {
27        None
28    } else {
29        match Picker::from_query_stdio() {
30            Ok(p) => Some(p),
31            Err(e) => {
32                tracing::debug!("Terminal image protocol detection failed: {e}");
33                None
34            }
35        }
36    };
37
38    let theme = theme::Theme::from_name(&config.theme);
39    let app = App::new(config, theme, picker)?;
40    event::run_event_loop(app)
41}