diff options
| author | krolxon <krolyxon@tutanota.com> | 2024-04-25 12:58:13 +0530 |
|---|---|---|
| committer | krolxon <krolyxon@tutanota.com> | 2024-04-25 12:58:13 +0530 |
| commit | f665c4e9f3b4eaa226b0c813f6845e247a4e6977 (patch) | |
| tree | 03119ed4587357a34f3728700f3a3e19ac89e1b2 /src/handler.rs | |
| parent | 4bc03ce8f4dea2ed6d68f2694bd095c9e3857e5e (diff) | |
better event handling with tick, search
Diffstat (limited to 'src/handler.rs')
| -rwxr-xr-x | src/handler.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/handler.rs b/src/handler.rs index 67121fb..fce3aa8 100755 --- a/src/handler.rs +++ b/src/handler.rs @@ -2,6 +2,10 @@ use std::time::Duration; use crate::app::{App, AppResult, SelectedTab}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use mpd::{Query, Term}; +use ratatui::style::Modifier; +use rust_fuzzy_search; +use simple_dmenu::dmenu; pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { match key_event.code { @@ -39,7 +43,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.queue_list.list.get(app.queue_list.index).unwrap(), ); app.conn.push(&song)?; - } SelectedTab::Playlists => { app.conn @@ -52,19 +55,16 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // Toggle Pause KeyCode::Char('p') => { app.conn.toggle_pause(); - app.conn.update_state(); } // Pause KeyCode::Char('s') => { app.conn.pause(); - app.conn.update_state(); } // Clear Queue KeyCode::Char('x') => { app.conn.conn.clear()?; - app.conn.update_state(); // app.update_queue(); } @@ -73,7 +73,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.conn.play_dmenu()?; } - // add to queue KeyCode::Char('a') => { let song = app.conn.get_song_with_only_filename( @@ -82,7 +81,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.conn.conn.push(&song)?; } - KeyCode::Right => { app.conn .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; @@ -138,6 +136,28 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // Delete highlighted song from the queue KeyCode::Char('d') => { app.conn.conn.delete(app.queue_list.index as u32)?; + app.update_queue(); + } + + KeyCode::Char('U') => { + app.conn.conn.update()?; + } + + KeyCode::Char('L') => { + let str = dmenu!(prompt "Search: "); + let list = app + .conn + .songs_filenames + .iter() + .map(|f| f.as_str()) + .collect::<Vec<&str>>(); + let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&str, &list) + .get(0) + .unwrap() + .clone(); + + let song = app.conn.get_song_with_only_filename(filename); + app.conn.push(&song)?; } _ => {} |
