Krolyxon
Commit 414e9fb

rmptui414e9fb

comply with clippy

Author
krolxon
Date
2024-06-13 15:31 +0530
Parent
dd39c7e
Commit
414e9fbbab29070afb884cdd61f0a34ce5b60532

+28 −33

5 files changed

  1. M src/app.rs +13 −15
  2. M src/browser.rs +3 −3
  3. M src/event/handler.rs +3 −4
  4. M src/event/pl_append_keys.rs +5 −7
  5. M src/ui.rs +4 −4
M src/app.rs View
@@ -29,7 +29,7 @@ pub struct App {
2929 pub pl_newname_input: String, // Stores the new name of the playlist
3030 pub pl_cursor_pos: usize, // Stores the cursor position for renaming playlist
3131
32− pub pl_new_pl_input: String, // Stores the name of new playlist to be created
32+ pub pl_new_pl_input: String, // Stores the name of new playlist to be created
3333 pub pl_new_pl_cursor_pos: usize, // Stores the cursor position of new playlist to be created
3434 pub pl_new_pl_songs_buffer: Vec<Song>, // Buffer for songs that need to be added to the newly created playlist
3535
@@ -101,8 +101,7 @@ impl App {
101101 self.update_queue();
102102
103103 // Deals with database update
104− if self.should_update_song_list {
105− if let None = self.conn.status.updating_db {
104+ if self.should_update_song_list && self.conn.status.updating_db.is_none() {
106105 // Update the songs list
107106 self.conn.songs_filenames = self
108107 .conn
@@ -115,7 +114,6 @@ impl App {
115114 self.browser.update_directory(&mut self.conn)?;
116115
117116 self.should_update_song_list = false;
118− }
119117 }
120118
121119 Ok(())
@@ -163,22 +161,22 @@ impl App {
163161 let file = format!("{}/{}", self.browser.path, content);
164162 let songs = self.conn.conn.listfiles(&file).unwrap_or_default();
165163 for (t, f) in songs.iter() {
166− if t == "file" {
167− if Path::new(&f).has_extension(&[
164+ if t == "file"
165+ && Path::new(&f).has_extension(&[
168166 "mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma",
169167 "mpc", "aiff", "dff", "mp2", "mka",
170− ]) {
171− let path = file.clone() + "/" + f;
172− let full_path = path.strip_prefix("./").unwrap_or_else(|| "");
173− let song = self.conn.get_song_with_only_filename(&full_path);
174− self.conn.conn.push(&song)?;
175− }
168+ ])
169+ {
170+ let path = file.clone() + "/" + f;
171+ let full_path = path.strip_prefix("./").unwrap_or("");
172+ let song = self.conn.get_song_with_only_filename(full_path);
173+ self.conn.conn.push(&song)?;
176174 }
177175 }
178176 } else if content_type == "file" {
179177 let mut status = false;
180178 for (i, song) in self.queue_list.list.clone().iter().enumerate() {
181− let song_path = song.file.split("/").last().unwrap_or_default();
179+ let song_path = song.file.split('/').last().unwrap_or_default();
182180 if song_path.eq(content) {
183181 self.conn.conn.delete(i as u32).unwrap();
184182 status = true;
@@ -253,7 +251,7 @@ impl App {
253251 let (t, path) = browser.filetree.get(browser.selected).unwrap();
254252 if t == "directory" {
255253 if path != "." {
256− browser.prev_path = browser.path.clone();
254+ browser.prev_path.clone_from(&browser.path);
257255 browser.path = browser.prev_path.clone() + "/" + path;
258256 browser.update_directory(&mut self.conn)?;
259257 browser.prev_selected = browser.selected;
@@ -261,7 +259,7 @@ impl App {
261259 }
262260 } else {
263261 let index = self.queue_list.list.iter().position(|x| {
264− let file = x.file.split("/").last().unwrap_or_default();
262+ let file = x.file.split('/').last().unwrap_or_default();
265263 file.eq(path)
266264 });
267265
M src/browser.rs View
@@ -32,7 +32,7 @@ impl FileBrowser {
3232 let mut file_vec: Vec<(String, String)> = vec![];
3333 let mut dir_vec: Vec<(String, String)> = vec![];
3434 for (t, f) in conn.conn.listfiles(self.path.as_str())?.into_iter() {
35− if t == "directory" && !f.starts_with(".") {
35+ if t == "directory" && !f.starts_with('.') {
3636 dir_vec.push((t, f));
3737 } else if t == "file"
3838 && Path::new(&f).has_extension(&[
@@ -73,7 +73,7 @@ impl FileBrowser {
7373 .lsinfo(Song {
7474 file: (self.path.clone() + "/" + song)
7575 .strip_prefix("./")
76− .unwrap_or_else(|| "")
76+ .unwrap_or("")
7777 .to_string(),
7878 ..Default::default()
7979 })
@@ -121,7 +121,7 @@ impl FileBrowser {
121121 self.update_directory(conn)?;
122122 }
123123 } else {
124− self.path = self.prev_path.clone();
124+ self.path.clone_from(&self.prev_path);
125125 self.update_directory(conn)?;
126126 }
127127
M src/event/handler.rs View
@@ -6,7 +6,7 @@ use crate::{
66 use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
77 use std::time::Duration;
88
9−use super::{pl_append_keys, pl_rename_keys, new_pl_keys, search_keys};
9+use super::{new_pl_keys, pl_append_keys, pl_rename_keys, search_keys};
1010
1111 pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
1212 // searching, playlist renaming, playlist appending
@@ -325,9 +325,8 @@ pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult<
325325 MouseEventKind::ScrollDown => app.handle_scroll_down(),
326326 MouseEventKind::Down(button) => {
327327 let (x, y) = (mouse_event.column, mouse_event.row);
328− match button {
329− crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?,
330− _ => {}
328+ if button == crossterm::event::MouseButton::Left {
329+ app.handle_mouse_left_click(x, y)?;
331330 }
332331 }
333332 _ => {}
M src/event/pl_append_keys.rs View
@@ -29,14 +29,14 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
2929 let option_song = songs.first();
3030 if let Some(song) = option_song {
3131 if *pl_name == "Current Playlist" {
32− app.conn.conn.push(&song)?;
32+ app.conn.conn.push(song)?;
3333 app.update_queue();
3434 } else if *pl_name == "New Playlist" {
3535 app.pl_new_pl_songs_buffer.clear();
3636 app.pl_new_pl_songs_buffer.push(song.clone());
3737 app.inputmode = InputMode::NewPlaylist;
3838 } else {
39− app.conn.add_to_playlist(pl_name, &song)?;
39+ app.conn.add_to_playlist(pl_name, song)?;
4040 }
4141 }
4242 }
@@ -47,7 +47,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
4747 if t == "file" {
4848 let short_path = f;
4949 if let Some(full_path) = app.conn.get_full_path(short_path) {
50− let song = app.conn.get_song_with_only_filename(&full_path);
50+ let song = app.conn.get_song_with_only_filename(full_path);
5151
5252 if *pl_name == "Current Playlist" {
5353 app.conn.conn.push(&song)?;
@@ -72,7 +72,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
7272 ])
7373 {
7474 let full_path = app.conn.get_full_path(f).unwrap_or_default();
75− let song = app.conn.get_song_with_only_filename(&full_path);
75+ let song = app.conn.get_song_with_only_filename(full_path);
7676 if *pl_name == "Current Playlist" {
7777 app.conn.conn.push(&song)?;
7878 } else if *pl_name == "New Playlist" {
@@ -98,9 +98,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
9898 for song in songs {
9999 // We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore.
100100 // So instead of panicking, we just ignore if the song does not exists
101− app.conn
102− .add_to_playlist(*pl_name, &song)
103− .unwrap_or_else(|_| {});
101+ app.conn.add_to_playlist(pl_name, &song).unwrap_or(());
104102 }
105103 }
106104 }
M src/ui.rs View
@@ -83,7 +83,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
8383
8484 let mut status: bool = false;
8585 for sn in app.queue_list.list.iter() {
86− let file = sn.file.split("/").last().unwrap_or_default();
86+ let file = sn.file.split('/').last().unwrap_or_default();
8787 if file.eq(s) {
8888 status = true;
8989 }
@@ -137,7 +137,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
137137 .alignment(Alignment::Right)
138138 }
139139 VolumeStatus::Muted(_v) => {
140− Title::from(format!("Muted").red()).alignment(Alignment::Right)
140+ Title::from("Muted".red()).alignment(Alignment::Right)
141141 }
142142 })
143143 .borders(Borders::ALL),
@@ -235,7 +235,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
235235 .alignment(Alignment::Right)
236236 }
237237 VolumeStatus::Muted(_v) => {
238− Title::from(format!("Muted").red()).alignment(Alignment::Right)
238+ Title::from("Muted".red()).alignment(Alignment::Right)
239239 }
240240 })
241241 .borders(Borders::ALL),
@@ -288,7 +288,7 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
288288 // Get the current playing state
289289 let mut state: String = String::new();
290290 if !app.queue_list.list.is_empty() {
291− state = app.conn.state.clone();
291+ state.clone_from(&app.conn.state);
292292 state.push(':');
293293 }
294294