octo-tui/src/main.rs
src/main.rsRaw
1mod api;
2mod app;
3mod artwork;
4mod config;
5mod downloads;
6mod model;
7mod player;
8mod playlists;
9#[cfg(test)]
10mod test_support;
11mod theme;
12mod ui;
13
14use anyhow::{Result, bail};
15use crossterm::event::{self, Event, KeyEventKind};
16use std::{path::PathBuf, sync::Arc, time::Duration};
17
18fn main() -> Result<()> {
19 let mut no_art = false;
20 let mut theme = None;
21 let mut config_path = None;
22 let mut args = std::env::args().skip(1);
23 while let Some(arg) = args.next() {
24 match arg.as_str() {
25 "--no-art" => no_art = true,
26 "--theme" => {
27 theme = Some(
28 args.next()
29 .ok_or_else(|| anyhow::anyhow!("--theme needs a name"))?
30 .parse::<theme::Theme>()?,
31 )
32 }
33 "--config" => {
34 config_path = Some(PathBuf::from(
35 args.next()
36 .ok_or_else(|| anyhow::anyhow!("--config needs a path"))?,
37 ))
38 }
39 "--help" | "-h" => {
40 println!(
41 "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."
42 );
43 return Ok(());
44 }
45 "--version" | "-V" => {
46 println!("octo-tui {}", env!("CARGO_PKG_VERSION"));
47 return Ok(());
48 }
49 _ => bail!("Unknown argument. Use --help for usage."),
50 }
51 }
52 let config = config::Config::load(config_path)?;
53 let volume = config.volume.unwrap_or(70);
54 let configured_theme = config
55 .theme
56 .as_deref()
57 .map(str::parse::<theme::Theme>)
58 .transpose()?;
59 let api = Arc::new(api::Api::new(config)?);
60 let mut app = app::App::new(api.clone(), volume);
61 if let Some(theme) = theme.or(configured_theme) {
62 app.theme = theme;
63 }
64 let mut terminal = ratatui::init();
65 if !no_art && let Some(font_size) = artwork::terminal_font_size() {
66 app.artwork = artwork::Artwork::new(api, font_size);
67 }
68 let result = run(&mut terminal, &mut app);
69 ratatui::restore();
70 app.save();
71 result
72}
73
74fn run(terminal: &mut ratatui::DefaultTerminal, app: &mut app::App) -> Result<()> {
75 while !app.quit {
76 app.tick();
77 terminal.draw(|frame| ui::draw(frame, app))?;
78 if event::poll(Duration::from_millis(100))?
79 && let Event::Key(key) = event::read()?
80 && key.kind != KeyEventKind::Release
81 {
82 app.key(key);
83 }
84 }
85 Ok(())
86}