aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/cli.rs43
-rwxr-xr-xsrc/connection.rs32
-rwxr-xr-xsrc/event/handler.rs4
-rwxr-xr-xsrc/lib.rs3
-rwxr-xr-xsrc/main.rs37
5 files changed, 6 insertions, 113 deletions
diff --git a/src/cli.rs b/src/cli.rs
deleted file mode 100755
index 2992952..0000000
--- a/src/cli.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-use clap::{Parser, Subcommand};
-
-#[derive(Parser, Debug)]
-#[clap(version, about, author = "krolyxon")]
-/// MPD client made with Rust
-pub struct Args {
- /// No TUI
- #[arg(short= 'n', default_value="false")]
- pub tui: bool,
-
- #[command(subcommand)]
- pub command: Option<Command>,
-}
-
-#[derive(Debug, Subcommand)]
-pub enum Command {
- #[command(arg_required_else_help = true, long_flag = "volume" , short_flag = 'v')]
- /// Set Volume
- Volume {
- vol: String,
- },
-
- /// Use dmenu for selection
- #[command(long_flag = "dmenu" , short_flag = 'd')]
- Dmenu,
-
- /// Use Fzf for selection
- #[command(long_flag = "fzf" , short_flag = 'f')]
- Fzf,
-
- /// Check Status
- #[command(long_flag = "status" , short_flag = 's')]
- Status,
-
- /// Pause playback
- #[command(long_flag = "pause" , short_flag = 'p')]
- Pause,
-
- /// Toggle Playback
- #[command(long_flag = "toggle" , short_flag = 't')]
- Toggle,
-
-}
diff --git a/src/connection.rs b/src/connection.rs
index 972ee10..9fde2e2 100755
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -61,18 +61,6 @@ impl Connection {
})
}
- /// Fzf prompt for selecting song
- pub fn play_fzf(&mut self) -> Result<()> {
- is_installed("fzf")?;
- let ss = &self.songs_filenames;
- let fzf_choice = rust_fzf::select(ss.clone(), Vec::new()).unwrap();
- let index = get_choice_index(&self.songs_filenames, fzf_choice.first().unwrap());
- let song = self.get_song_with_only_filename(ss.get(index).unwrap());
- self.push(&song)?;
-
- Ok(())
- }
-
/// Dmenu prompt for selecting songs
pub fn play_dmenu(&mut self) -> Result<()> {
is_installed("dmenu")?;
@@ -178,27 +166,7 @@ impl Connection {
return Some(self.songs_filenames.get(i).unwrap().to_string());
}
}
-
None
-
- // Ok(filename.to_string())
- }
-
- /// Print status to stdout
- pub fn status(&mut self) {
- let current_song = self.conn.currentsong();
- let status = self.conn.status().unwrap();
-
- if current_song.is_ok() && status.state != State::Stop {
- let song = current_song.unwrap();
- if let Some(s) = song {
- println!("{} - {}", s.artist.unwrap(), s.title.unwrap());
- }
- }
- println!(
- "volume: {}\trepeat: {}\trandom: {}\tsingle: {}\tconsume: {}",
- status.volume, status.repeat, status.random, status.single, status.consume
- );
}
/// Gives title of current playing song
diff --git a/src/event/handler.rs b/src/event/handler.rs
index 0978458..3663006 100755
--- a/src/event/handler.rs
+++ b/src/event/handler.rs
@@ -177,7 +177,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.queue_list.index as u32
} else {
app.queue_list.index += 1;
- (current + 1) as u32
+ current + 1
};
app.conn.conn.swap(current, next)?;
app.update_queue();
@@ -190,7 +190,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.queue_list.index as u32
} else {
app.queue_list.index -= 1;
- (current - 1) as u32
+ current - 1
};
app.conn.conn.swap(current, prev)?;
app.update_queue();
diff --git a/src/lib.rs b/src/lib.rs
index f06847f..6744922 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,3 @@
-/// Command line interface (deprecated)
-pub mod cli;
-
/// Handle mpd connection
pub mod connection;
diff --git a/src/main.rs b/src/main.rs
index ce64c85..d8441d3 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,50 +1,21 @@
-#![allow(unused_imports)]
-use clap::Parser;
-use rmptui::app;
use rmptui::app::App;
use rmptui::app::AppResult;
-use rmptui::cli::Args;
-use rmptui::cli::Command;
-use rmptui::connection::Connection;
use rmptui::event::event::Event;
use rmptui::event::event::EventHandler;
use rmptui::event::handler;
use rmptui::tui;
use std::env;
use std::io;
-
-use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
-use ratatui::{
- prelude::*,
- symbols::border,
- widgets::{block::*, *},
-};
+use ratatui::prelude::*;
pub type Result<T> = core::result::Result<T, Error>;
pub type Error = Box<dyn std::error::Error>;
fn main() -> AppResult<()> {
- let args = Args::parse();
let env_host = env::var("MPD_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let env_port = env::var("MPD_PORT").unwrap_or_else(|_| "6600".to_string());
let mut app = App::builder(format!("{}:{}", env_host, env_port).as_str())?;
- if !args.tui {
- handle_tui(&mut app)?;
- } else {
- match args.command {
- Some(Command::Dmenu) => app.conn.play_dmenu()?,
- Some(Command::Fzf) => app.conn.play_fzf().unwrap(),
- Some(Command::Status) => app.conn.status(),
- Some(Command::Pause) => app.conn.pause(),
- Some(Command::Toggle) => app.conn.toggle_pause(),
- _ => {}
- }
- }
- Ok(())
-}
-
-pub fn handle_tui(app: &mut App) -> AppResult<()> {
let backend = CrosstermBackend::new(io::stderr());
let terminal = Terminal::new(backend)?;
let events = EventHandler::new(1000);
@@ -52,14 +23,14 @@ pub fn handle_tui(app: &mut App) -> AppResult<()> {
let mut tui = tui::Tui::new(terminal, events);
tui.init()?;
- // update the directory
+ // initial directory read
app.browser.update_directory(&mut app.conn).unwrap();
while app.running {
- tui.draw(app)?;
+ tui.draw(&mut app)?;
match tui.events.next()? {
Event::Tick => app.tick(),
- Event::Key(key_event) => handler::handle_key_events(key_event, app)?,
+ Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
Event::Mouse(_) => {}
Event::Resize(_, _) => {}
}