rmptui8269766
delete this random (L) function, add comments
+17 −20
2 files changed
- M src/handler.rs +13 −18
- M src/ui.rs +4 −2
| @@ -4,7 +4,7 @@ use crate::{ | |||
| 4 | 4 | app::{App, AppResult, SelectedTab}, | |
| 5 | 5 | ui::InputMode, | |
| 6 | 6 | }; | |
| 7 | − | use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers}; | |
| 7 | + | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | |
| 8 | 8 | use rust_fuzzy_search::{self, fuzzy_search_sorted}; | |
| 9 | 9 | use simple_dmenu::dmenu; | |
| 10 | 10 | ||
| @@ -72,6 +72,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 72 | 72 | } | |
| 73 | 73 | } else { | |
| 74 | 74 | match key_event.code { | |
| 75 | + | // Quit | |
| 75 | 76 | KeyCode::Char('q') | KeyCode::Esc => app.quit(), | |
| 76 | 77 | KeyCode::Char('c') | KeyCode::Char('C') => { | |
| 77 | 78 | if key_event.modifiers == KeyModifiers::CONTROL { | |
| @@ -83,18 +84,21 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 83 | 84 | } | |
| 84 | 85 | } | |
| 85 | 86 | ||
| 87 | + | // Go Up | |
| 86 | 88 | KeyCode::Char('j') | KeyCode::Down => match app.selected_tab { | |
| 87 | 89 | SelectedTab::DirectoryBrowser => app.browser.next(), | |
| 88 | 90 | SelectedTab::Queue => app.queue_list.next(), | |
| 89 | 91 | SelectedTab::Playlists => app.pl_list.next(), | |
| 90 | 92 | }, | |
| 91 | 93 | ||
| 94 | + | // Go down | |
| 92 | 95 | KeyCode::Char('k') | KeyCode::Up => match app.selected_tab { | |
| 93 | 96 | SelectedTab::DirectoryBrowser => app.browser.prev(), | |
| 94 | 97 | SelectedTab::Queue => app.queue_list.prev(), | |
| 95 | 98 | SelectedTab::Playlists => app.pl_list.prev(), | |
| 96 | 99 | }, | |
| 97 | 100 | ||
| 101 | + | // Next directory | |
| 98 | 102 | KeyCode::Enter | KeyCode::Char('l') => { | |
| 99 | 103 | // app.update_queue(); | |
| 100 | 104 | ||
| @@ -117,6 +121,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 117 | 121 | app.conn.update_status(); | |
| 118 | 122 | } | |
| 119 | 123 | ||
| 124 | + | // head back to previous directory | |
| 120 | 125 | KeyCode::Char('h') => match app.selected_tab { | |
| 121 | 126 | SelectedTab::DirectoryBrowser => { | |
| 122 | 127 | app.browser.handle_go_back(&mut app.conn)?; | |
| @@ -204,26 +209,32 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 204 | 209 | app.conn.conn.seek(place, pos)?; | |
| 205 | 210 | } | |
| 206 | 211 | ||
| 212 | + | // Cycle through tabs | |
| 207 | 213 | KeyCode::Tab => { | |
| 208 | 214 | app.cycle_tabls(); | |
| 209 | 215 | } | |
| 210 | 216 | ||
| 217 | + | // Directory browser tab | |
| 211 | 218 | KeyCode::Char('1') => { | |
| 212 | 219 | app.selected_tab = SelectedTab::DirectoryBrowser; | |
| 213 | 220 | } | |
| 214 | 221 | ||
| 222 | + | // Playing queue tab | |
| 215 | 223 | KeyCode::Char('2') => { | |
| 216 | 224 | app.selected_tab = SelectedTab::Queue; | |
| 217 | 225 | } | |
| 218 | 226 | ||
| 227 | + | // Playlists tab | |
| 219 | 228 | KeyCode::Char('3') => { | |
| 220 | 229 | app.selected_tab = SelectedTab::Playlists; | |
| 221 | 230 | } | |
| 222 | 231 | ||
| 232 | + | // Play next song | |
| 223 | 233 | KeyCode::Char('>') => { | |
| 224 | 234 | app.conn.conn.next()?; | |
| 225 | 235 | } | |
| 226 | 236 | ||
| 237 | + | // Play previous song | |
| 227 | 238 | KeyCode::Char('<') => { | |
| 228 | 239 | app.conn.conn.prev()?; | |
| 229 | 240 | } | |
| @@ -251,27 +262,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 251 | 262 | app.update_queue(); | |
| 252 | 263 | } | |
| 253 | 264 | ||
| 265 | + | // Update MPD database | |
| 254 | 266 | KeyCode::Char('U') => { | |
| 255 | 267 | app.conn.conn.update()?; | |
| 256 | 268 | } | |
| 257 | 269 | ||
| 258 | − | KeyCode::Char('L') => { | |
| 259 | − | let str = dmenu!(prompt "Search: "); | |
| 260 | − | let list = app | |
| 261 | − | .conn | |
| 262 | − | .songs_filenames | |
| 263 | − | .iter() | |
| 264 | − | .map(|f| f.as_str()) | |
| 265 | − | .collect::<Vec<&str>>(); | |
| 266 | − | let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&str, &list) | |
| 267 | − | .get(0) | |
| 268 | − | .unwrap() | |
| 269 | − | .clone(); | |
| 270 | − | ||
| 271 | − | let song = app.conn.get_song_with_only_filename(filename); | |
| 272 | − | app.conn.push(&song)?; | |
| 273 | − | } | |
| 274 | − | ||
| 275 | 270 | // Search for songs | |
| 276 | 271 | KeyCode::Char('/') => { | |
| 277 | 272 | app.inputmode = InputMode::toggle_editing_states(&app.inputmode); | |
| @@ -78,6 +78,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 78 | 78 | Style::new() | |
| 79 | 79 | .fg(Color::Cyan) | |
| 80 | 80 | .bg(Color::Black) | |
| 81 | + | .add_modifier(Modifier::BOLD) | |
| 81 | 82 | .add_modifier(Modifier::REVERSED), | |
| 82 | 83 | ) | |
| 83 | 84 | .highlight_symbol(">>") | |
| @@ -103,10 +104,10 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 103 | 104 | Style::new() | |
| 104 | 105 | .fg(Color::Cyan) | |
| 105 | 106 | .bg(Color::Black) | |
| 107 | + | .add_modifier(Modifier::BOLD) | |
| 106 | 108 | .add_modifier(Modifier::REVERSED), | |
| 107 | 109 | ) | |
| 108 | − | .highlight_symbol(">>") | |
| 109 | − | .repeat_highlight_symbol(true); | |
| 110 | + | .highlight_symbol(">>"); | |
| 110 | 111 | ||
| 111 | 112 | queue_state.select(Some(app.queue_list.index)); | |
| 112 | 113 | frame.render_stateful_widget(list, size, &mut queue_state); | |
| @@ -129,6 +130,7 @@ fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 129 | 130 | Style::new() | |
| 130 | 131 | .fg(Color::Cyan) | |
| 131 | 132 | .bg(Color::Black) | |
| 133 | + | .add_modifier(Modifier::BOLD) | |
| 132 | 134 | .add_modifier(Modifier::REVERSED), | |
| 133 | 135 | ) | |
| 134 | 136 | .highlight_symbol(">>") | |