Krolyxon
Commit ba154a3

rmptuisrcmain.rs

75 lines · 2.0 KB · Rust

1#![allow(unused_imports)]
2use clap::Parser;
3use rmptui::app;
4use rmptui::app::App;
5use rmptui::app::AppResult;
6use rmptui::cli::Args;
7use rmptui::cli::Command;
8use rmptui::connection::Connection;
9use rmptui::event::Event;
10use rmptui::event::EventHandler;
11use rmptui::handler;
12use rmptui::song::RSong;
13use rmptui::tui;
14use std::io;
15
16use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
17use ratatui::{
18 prelude::*,
19 symbols::border,
20 widgets::{block::*, *},
21};
22
23pub type Result<T> = core::result::Result<T, Error>;
24pub type Error = Box<dyn std::error::Error>;
25
26fn main() -> AppResult<()> {
27 let args = Args::parse();
28 let mut app = App::builder("127.0.0.1:6600")?;
29
30 if !args.tui {
31 handle_tui(&mut app)?;
32 } else {
33 match args.command {
34 Some(Command::Dmenu) => app.conn.play_dmenu()?,
35 Some(Command::Fzf) => app.conn.play_fzf().unwrap(),
36 Some(Command::Status) => app.conn.status(),
37 Some(Command::Pause) => app.conn.pause(),
38 Some(Command::Toggle) => app.conn.toggle_pause(),
39 _ => {
40 // let mut vec: Vec<RSong> = Vec::new();
41 // for filename in app.conn.songs_filenames {
42 // let song = RSong::new(&mut app.conn.conn, filename);
43 // vec.push(song);
44 // }
45 // println!("{:#?}", vec);
46
47 }
48 }
49 }
50 Ok(())
51}
52
53pub fn handle_tui(app: &mut App) -> AppResult<()> {
54 let backend = CrosstermBackend::new(io::stderr());
55 let terminal = Terminal::new(backend)?;
56 let events = EventHandler::new(1000);
57
58 let mut tui = tui::Tui::new(terminal, events);
59 tui.init()?;
60
61 // update the directory
62 app.browser.update_directory(&mut app.conn).unwrap();
63
64 while app.running {
65 tui.draw(app)?;
66 match tui.events.next()? {
67 Event::Tick => app.tick(),
68 Event::Key(key_event) => handler::handle_key_events(key_event, app)?,
69 Event::Mouse(_) => {}
70 Event::Resize(_, _) => {}
71 }
72 }
73
74 Ok(())
75}