Krolyxon
Commit 8269766

rmptui8269766

delete this random (L) function, add comments

Author
krolxon
Date
2024-04-26 21:12 +0530
Parent
ba154a3
Commit
8269766147962df1fce10c6617baf7d5d9300f40

+17 −20

2 files changed

  1. M src/handler.rs +13 −18
  2. M src/ui.rs +4 −2
M src/handler.rs View
@@ -4,7 +4,7 @@ use crate::{
44 app::{App, AppResult, SelectedTab},
55 ui::InputMode,
66 };
7−use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
7+use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
88 use rust_fuzzy_search::{self, fuzzy_search_sorted};
99 use simple_dmenu::dmenu;
1010
@@ -72,6 +72,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
7272 }
7373 } else {
7474 match key_event.code {
75+ // Quit
7576 KeyCode::Char('q') | KeyCode::Esc => app.quit(),
7677 KeyCode::Char('c') | KeyCode::Char('C') => {
7778 if key_event.modifiers == KeyModifiers::CONTROL {
@@ -83,18 +84,21 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
8384 }
8485 }
8586
87+ // Go Up
8688 KeyCode::Char('j') | KeyCode::Down => match app.selected_tab {
8789 SelectedTab::DirectoryBrowser => app.browser.next(),
8890 SelectedTab::Queue => app.queue_list.next(),
8991 SelectedTab::Playlists => app.pl_list.next(),
9092 },
9193
94+ // Go down
9295 KeyCode::Char('k') | KeyCode::Up => match app.selected_tab {
9396 SelectedTab::DirectoryBrowser => app.browser.prev(),
9497 SelectedTab::Queue => app.queue_list.prev(),
9598 SelectedTab::Playlists => app.pl_list.prev(),
9699 },
97100
101+ // Next directory
98102 KeyCode::Enter | KeyCode::Char('l') => {
99103 // app.update_queue();
100104
@@ -117,6 +121,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
117121 app.conn.update_status();
118122 }
119123
124+ // head back to previous directory
120125 KeyCode::Char('h') => match app.selected_tab {
121126 SelectedTab::DirectoryBrowser => {
122127 app.browser.handle_go_back(&mut app.conn)?;
@@ -204,26 +209,32 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
204209 app.conn.conn.seek(place, pos)?;
205210 }
206211
212+ // Cycle through tabs
207213 KeyCode::Tab => {
208214 app.cycle_tabls();
209215 }
210216
217+ // Directory browser tab
211218 KeyCode::Char('1') => {
212219 app.selected_tab = SelectedTab::DirectoryBrowser;
213220 }
214221
222+ // Playing queue tab
215223 KeyCode::Char('2') => {
216224 app.selected_tab = SelectedTab::Queue;
217225 }
218226
227+ // Playlists tab
219228 KeyCode::Char('3') => {
220229 app.selected_tab = SelectedTab::Playlists;
221230 }
222231
232+ // Play next song
223233 KeyCode::Char('>') => {
224234 app.conn.conn.next()?;
225235 }
226236
237+ // Play previous song
227238 KeyCode::Char('<') => {
228239 app.conn.conn.prev()?;
229240 }
@@ -251,27 +262,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
251262 app.update_queue();
252263 }
253264
265+ // Update MPD database
254266 KeyCode::Char('U') => {
255267 app.conn.conn.update()?;
256268 }
257269
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−
275270 // Search for songs
276271 KeyCode::Char('/') => {
277272 app.inputmode = InputMode::toggle_editing_states(&app.inputmode);
M src/ui.rs View
@@ -78,6 +78,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
7878 Style::new()
7979 .fg(Color::Cyan)
8080 .bg(Color::Black)
81+ .add_modifier(Modifier::BOLD)
8182 .add_modifier(Modifier::REVERSED),
8283 )
8384 .highlight_symbol(">>")
@@ -103,10 +104,10 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
103104 Style::new()
104105 .fg(Color::Cyan)
105106 .bg(Color::Black)
107+ .add_modifier(Modifier::BOLD)
106108 .add_modifier(Modifier::REVERSED),
107109 )
108− .highlight_symbol(">>")
109− .repeat_highlight_symbol(true);
110+ .highlight_symbol(">>");
110111
111112 queue_state.select(Some(app.queue_list.index));
112113 frame.render_stateful_widget(list, size, &mut queue_state);
@@ -129,6 +130,7 @@ fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) {
129130 Style::new()
130131 .fg(Color::Cyan)
131132 .bg(Color::Black)
133+ .add_modifier(Modifier::BOLD)
132134 .add_modifier(Modifier::REVERSED),
133135 )
134136 .highlight_symbol(">>")