rmptui9555328
remove queue struct, and use generics of ContentList
+8 −53
4 files changed
- M src/app.rs +5 −6
- M src/lib.rs +0 −3
- D src/queue.rs +0 −41
- M src/ui.rs +3 −3
| @@ -3,7 +3,6 @@ use std::time::Duration; | |||
| 3 | 3 | use crate::browser::FileBrowser; | |
| 4 | 4 | use crate::connection::Connection; | |
| 5 | 5 | use crate::list::ContentList; | |
| 6 | − | use crate::queue::Queue; | |
| 7 | 6 | use crate::ui::InputMode; | |
| 8 | 7 | use mpd::{Client, Song}; | |
| 9 | 8 | ||
| @@ -16,10 +15,10 @@ pub struct App { | |||
| 16 | 15 | /// check if app is running | |
| 17 | 16 | pub running: bool, | |
| 18 | 17 | pub conn: Connection, | |
| 19 | − | pub browser: FileBrowser, // Directory browser | |
| 20 | − | pub queue_list: Queue, // Stores the current playing queue | |
| 21 | − | pub pl_list: ContentList<String>, // Stores list of playlists | |
| 22 | − | pub selected_tab: SelectedTab, // Used to switch between tabs | |
| 18 | + | pub browser: FileBrowser, // Directory browser | |
| 19 | + | pub queue_list: ContentList<Song>, // Stores the current playing queue | |
| 20 | + | pub pl_list: ContentList<String>, // Stores list of playlists | |
| 21 | + | pub selected_tab: SelectedTab, // Used to switch between tabs | |
| 23 | 22 | ||
| 24 | 23 | // Search | |
| 25 | 24 | pub inputmode: InputMode, // Defines input mode, Normal or Search | |
| @@ -44,7 +43,7 @@ pub enum SelectedTab { | |||
| 44 | 43 | impl App { | |
| 45 | 44 | pub fn builder(addrs: &str) -> AppResult<Self> { | |
| 46 | 45 | let mut conn = Connection::new(addrs).unwrap(); | |
| 47 | − | let mut queue_list = Queue::new(); | |
| 46 | + | let mut queue_list = ContentList::new(); | |
| 48 | 47 | let mut pl_list = ContentList::new(); | |
| 49 | 48 | pl_list.list = Self::get_playlist(&mut conn.conn)?; | |
| 50 | 49 | ||
| @@ -24,6 +24,3 @@ pub mod handler; | |||
| 24 | 24 | ||
| 25 | 25 | /// Application | |
| 26 | 26 | pub mod app; | |
| 27 | − | ||
| 28 | − | /// The Queue structure | |
| 29 | − | pub mod queue; | |
| @@ -1,41 +0,0 @@ | |||
| 1 | − | use mpd::Song; | |
| 2 | − | ||
| 3 | − | #[derive(Debug)] | |
| 4 | − | pub struct Queue { | |
| 5 | − | pub list: Vec<Song>, | |
| 6 | − | pub index: usize, | |
| 7 | − | } | |
| 8 | − | ||
| 9 | − | impl Queue { | |
| 10 | − | pub fn new() -> Self { | |
| 11 | − | Queue { | |
| 12 | − | list: Vec::new(), | |
| 13 | − | index: 0, | |
| 14 | − | } | |
| 15 | − | } | |
| 16 | − | ||
| 17 | − | // Go to next item in list | |
| 18 | − | pub fn next(&mut self) { | |
| 19 | − | let len = self.list.len(); | |
| 20 | − | if len != 0 && self.index < len - 1 { | |
| 21 | − | self.index += 1; | |
| 22 | − | } | |
| 23 | − | } | |
| 24 | − | ||
| 25 | − | /// Go to previous item in list | |
| 26 | − | pub fn prev(&mut self) { | |
| 27 | − | if self.index != 0 { | |
| 28 | − | self.index -= 1; | |
| 29 | − | } | |
| 30 | − | } | |
| 31 | − | ||
| 32 | − | pub fn reset_index(&mut self) { | |
| 33 | − | self.index = 0; | |
| 34 | − | } | |
| 35 | − | } | |
| 36 | − | ||
| 37 | − | impl Default for Queue { | |
| 38 | − | fn default() -> Self { | |
| 39 | − | Self::new() | |
| 40 | − | } | |
| 41 | − | } | |
| @@ -362,9 +362,9 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) { | |||
| 362 | 362 | let table = Table::new( | |
| 363 | 363 | rows, | |
| 364 | 364 | vec![ | |
| 365 | − | Constraint::Min(40), | |
| 366 | − | Constraint::Percentage(40), | |
| 367 | − | Constraint::Percentage(20), | |
| 365 | + | Constraint::Min(48), | |
| 366 | + | Constraint::Percentage(48), | |
| 367 | + | Constraint::Percentage(4), | |
| 368 | 368 | ], | |
| 369 | 369 | ) | |
| 370 | 370 | .block(title) | |