Krolyxon
Commit 9555328

rmptui9555328

remove queue struct, and use generics of ContentList

Author
krolxon
Date
2024-05-01 12:08 +0530
Parent
b29846f
Commit
955532893fc6db5a78f88ef2a2700dec56cd3012

+8 −53

4 files changed

  1. M src/app.rs +5 −6
  2. M src/lib.rs +0 −3
  3. D src/queue.rs +0 −41
  4. M src/ui.rs +3 −3
M src/app.rs View
@@ -3,7 +3,6 @@ use std::time::Duration;
33 use crate::browser::FileBrowser;
44 use crate::connection::Connection;
55 use crate::list::ContentList;
6−use crate::queue::Queue;
76 use crate::ui::InputMode;
87 use mpd::{Client, Song};
98
@@ -16,10 +15,10 @@ pub struct App {
1615 /// check if app is running
1716 pub running: bool,
1817 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
2322
2423 // Search
2524 pub inputmode: InputMode, // Defines input mode, Normal or Search
@@ -44,7 +43,7 @@ pub enum SelectedTab {
4443 impl App {
4544 pub fn builder(addrs: &str) -> AppResult<Self> {
4645 let mut conn = Connection::new(addrs).unwrap();
47− let mut queue_list = Queue::new();
46+ let mut queue_list = ContentList::new();
4847 let mut pl_list = ContentList::new();
4948 pl_list.list = Self::get_playlist(&mut conn.conn)?;
5049
M src/lib.rs View
@@ -24,6 +24,3 @@ pub mod handler;
2424
2525 /// Application
2626 pub mod app;
27−
28−/// The Queue structure
29−pub mod queue;
D src/queue.rs View
@@ -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−}
M src/ui.rs View
@@ -362,9 +362,9 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
362362 let table = Table::new(
363363 rows,
364364 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),
368368 ],
369369 )
370370 .block(title)