aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-04-29 23:20:02 +0530
committerkrolxon <krolyxon@tutanota.com>2024-04-29 23:20:02 +0530
commit87bb8e9473194b47c9f52e49c7fe2b632bd36aef (patch)
tree93c29be7780a6f3677409ad4b1f349ae591dc8d0
parentc047f63cd1c727c36c61acacba073eb03b7f8617 (diff)
remove redundant functions and add comments
-rwxr-xr-xsrc/app.rs36
-rwxr-xr-xsrc/browser.rs5
-rwxr-xr-xsrc/connection.rs5
-rwxr-xr-xsrc/error.rs6
-rwxr-xr-xsrc/handler.rs16
5 files changed, 34 insertions, 34 deletions
diff --git a/src/app.rs b/src/app.rs
index e38222d..35661e1 100755
--- a/src/app.rs
+++ b/src/app.rs
@@ -15,17 +15,18 @@ pub struct App {
/// check if app is running
pub running: bool,
pub conn: Connection,
- pub queue_list: ContentList<String>,
- pub pl_list: ContentList<String>,
- pub selected_tab: SelectedTab,
- pub browser: FileBrowser,
+ pub browser: FileBrowser, // Directory browser
+ pub queue_list: ContentList<String>, // Stores the current playing queue
+ pub pl_list: ContentList<String>, // Stores list of playlists
+ pub selected_tab: SelectedTab, // Used to switch between tabs
// Search
- pub inputmode: InputMode,
- pub search_input: String,
- pub cursor_position: usize,
+ pub inputmode: InputMode, // Defines input mode, Normal or Search
+ pub search_input: String, // Stores the userinput to be searched
+ pub cursor_position: usize, // Stores the cursor position
- // add to playlists
+ // playlist variables
+ // used to show playlist popup
pub playlist_popup: bool,
pub append_list: ContentList<String>,
}
@@ -90,12 +91,13 @@ impl App {
});
}
+ // Rescan the queue into queue_list
pub fn update_queue(&mut self) {
self.queue_list.list.clear();
Self::get_queue(&mut self.conn, &mut self.queue_list.list);
}
- pub fn get_playlist(conn: &mut Client) -> AppResult<Vec<String>> {
+ fn get_playlist(conn: &mut Client) -> AppResult<Vec<String>> {
let list: Vec<String> = conn.playlists()?.iter().map(|p| p.clone().name).collect();
Ok(list)
}
@@ -110,11 +112,7 @@ impl App {
Ok(list)
}
- pub fn update_playlist(&mut self) -> AppResult<()> {
- Self::get_playlist(&mut self.conn.conn)?;
- Ok(())
- }
-
+ /// Handles the <Space> event key
pub fn handle_add_or_remove_from_current_playlist(&mut self) -> AppResult<()> {
match self.selected_tab {
SelectedTab::DirectoryBrowser => {
@@ -170,6 +168,7 @@ impl App {
Ok(())
}
+ /// Cycle through tabs
pub fn cycle_tabls(&mut self) {
self.selected_tab = match self.selected_tab {
SelectedTab::Queue => SelectedTab::DirectoryBrowser,
@@ -178,6 +177,7 @@ impl App {
};
}
+ /// handles the Enter event on the directory browser
pub fn handle_enter(&mut self) -> AppResult<()> {
let browser = &mut self.browser;
let (t, path) = browser.filetree.get(browser.selected).unwrap();
@@ -218,14 +218,6 @@ impl App {
Ok(())
}
- pub fn search_song(&mut self) -> AppResult<()> {
- if let Some(filename) = self.conn.get_full_path(&self.search_input) {
- let song = self.conn.get_song_with_only_filename(&filename);
- self.conn.push(&song)?;
- }
- Ok(())
- }
-
// Cursor movements
pub fn move_cursor_left(&mut self) {
let cursor_moved_left = self.cursor_position.saturating_sub(1);
diff --git a/src/browser.rs b/src/browser.rs
index 212618e..08b0006 100755
--- a/src/browser.rs
+++ b/src/browser.rs
@@ -6,6 +6,7 @@ use mpd::Song;
use crate::{app::AppResult, connection::Connection};
#[derive(Debug)]
+/// struct for working with directory browser tab in rmptui
pub struct FileBrowser {
pub filetree: Vec<(String, String)>,
pub selected: usize,
@@ -61,9 +62,10 @@ impl FileBrowser {
}
}
+
+ // Add metadata
dir_vec.extend(file_vec);
self.filetree = dir_vec;
-
self.songs.clear();
for (t, song) in self.filetree.iter() {
if t == "file" {
@@ -121,6 +123,7 @@ impl FileBrowser {
// }
}
+ /// handles going back event
pub fn handle_go_back(&mut self, conn: &mut Connection) -> AppResult<()> {
if self.prev_path != "." {
let r = self.path.rfind("/").unwrap();
diff --git a/src/connection.rs b/src/connection.rs
index 5cba89d..01d5d26 100755
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -8,6 +8,7 @@ pub type Result<T> = core::result::Result<T, Error>;
pub type Error = Box<dyn std::error::Error>;
#[derive(Debug)]
+/// struct storing the mpd Client related stuff
pub struct Connection {
pub conn: Client,
pub songs_filenames: Vec<String>,
@@ -26,7 +27,7 @@ impl Connection {
let mut conn = Client::connect(addrs).unwrap();
let empty_song = Song {
- file: "No Song playing or in Queue".to_string(),
+ file: "No Song playing or in Queue".to_string(),
..Default::default()
};
@@ -86,7 +87,7 @@ impl Connection {
/// Update status
pub fn update_status(&mut self) {
let status = self.conn.status().unwrap();
- let empty_song = self.get_song_with_only_filename("No Song playing or in Queue");
+ let empty_song = self.get_song_with_only_filename("No Song playing or in Queue");
let current_song = self
.conn
.currentsong()
diff --git a/src/error.rs b/src/error.rs
deleted file mode 100755
index 1e5b119..0000000
--- a/src/error.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-#[derive(Debug)]
-pub enum Error {
- DmenuNotInstalled,
- FzfNotInstalled,
-}
-
diff --git a/src/handler.rs b/src/handler.rs
index 8a7e7ca..a5c4edb 100755
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -1,12 +1,11 @@
use crate::browser::FileExtension;
-use std::{path::Path, time::Duration};
-
use crate::{
app::{App, AppResult, SelectedTab},
ui::InputMode,
};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use rust_fuzzy_search::{self, fuzzy_search_sorted};
+use std::{path::Path, time::Duration};
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
if app.inputmode == InputMode::Editing {
@@ -65,6 +64,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
}
}
+ // Keybind for searching
+ //
+ // Keybinds for when the search prompt is visible
match key_event.code {
KeyCode::Esc => {
app.inputmode = InputMode::Normal;
@@ -108,6 +110,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
_ => {}
}
+
+ // Playlist popup keybinds
+ //
+ // Keybind for when the "append to playlist" popup is visible
} else if app.playlist_popup {
match key_event.code {
KeyCode::Char('q') | KeyCode::Esc => {
@@ -183,6 +189,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
_ => {}
}
} else {
+ // Global keymaps
+ //
+ // Keymaps related to all the tabs
match key_event.code {
// Quit
KeyCode::Char('q') => app.quit(),
@@ -343,7 +352,8 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// Update MPD database
KeyCode::Char('U') => {
- app.conn.conn.update()?;
+ app.conn.conn.rescan()?;
+ app.browser.update_directory(&mut app.conn)?;
}
// Search for songs