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