mod api; mod app; mod artwork; mod config; mod downloads; mod model; mod player; mod playlists; #[cfg(test)] mod test_support; mod theme; mod ui; use anyhow::{Result, bail}; use crossterm::event::{self, Event, KeyEventKind}; use std::{path::PathBuf, sync::Arc, time::Duration}; fn main() -> Result<()> { let mut no_art = false; let mut theme = None; let mut config_path = None; let mut args = std::env::args().skip(1); while let Some(arg) = args.next() { match arg.as_str() { "--no-art" => no_art = true, "--theme" => { theme = Some( args.next() .ok_or_else(|| anyhow::anyhow!("--theme needs a name"))? .parse::()?, ) } "--config" => { config_path = Some(PathBuf::from( args.next() .ok_or_else(|| anyhow::anyhow!("--config needs a path"))?, )) } "--help" | "-h" => { println!( "octo-tui [--config PATH] [--theme NAME] [--no-art]\n\nVim-friendly Octo / Subsonic music player. Playback requires mpv.\n\nConfigure ~/.config/octo-tui/config.toml or set:\n OCTO_SERVER, OCTO_USERNAME, OCTO_PASSWORD (or OCTO_API_KEY)\n\nThemes: dark, monokai, spotifyish (default), nord, gruvbox, daylight, paper. Press t to cycle.\nCovers: SIXEL detected automatically; --no-art disables it.\nPress ? in the TUI for shortcuts." ); return Ok(()); } "--version" | "-V" => { println!("octo-tui {}", env!("CARGO_PKG_VERSION")); return Ok(()); } _ => bail!("Unknown argument. Use --help for usage."), } } let config = config::Config::load(config_path)?; let volume = config.volume.unwrap_or(70); let configured_theme = config .theme .as_deref() .map(str::parse::) .transpose()?; let api = Arc::new(api::Api::new(config)?); let mut app = app::App::new(api.clone(), volume); if let Some(theme) = theme.or(configured_theme) { app.theme = theme; } let mut terminal = ratatui::init(); if !no_art && let Some(font_size) = artwork::terminal_font_size() { app.artwork = artwork::Artwork::new(api, font_size); } let result = run(&mut terminal, &mut app); ratatui::restore(); app.save(); result } fn run(terminal: &mut ratatui::DefaultTerminal, app: &mut app::App) -> Result<()> { while !app.quit { app.tick(); terminal.draw(|frame| ui::draw(frame, app))?; if event::poll(Duration::from_millis(100))? && let Event::Key(key) = event::read()? && key.kind != KeyEventKind::Release { app.key(key); } } Ok(()) }