remove queue struct, and use generics of ContentList
This commit is contained in:
parent
b29846fb72
commit
955532893f
11
src/app.rs
11
src/app.rs
|
|
@ -3,7 +3,6 @@ use std::time::Duration;
|
||||||
use crate::browser::FileBrowser;
|
use crate::browser::FileBrowser;
|
||||||
use crate::connection::Connection;
|
use crate::connection::Connection;
|
||||||
use crate::list::ContentList;
|
use crate::list::ContentList;
|
||||||
use crate::queue::Queue;
|
|
||||||
use crate::ui::InputMode;
|
use crate::ui::InputMode;
|
||||||
use mpd::{Client, Song};
|
use mpd::{Client, Song};
|
||||||
|
|
||||||
|
|
@ -16,10 +15,10 @@ pub struct App {
|
||||||
/// check if app is running
|
/// check if app is running
|
||||||
pub running: bool,
|
pub running: bool,
|
||||||
pub conn: Connection,
|
pub conn: Connection,
|
||||||
pub browser: FileBrowser, // Directory browser
|
pub browser: FileBrowser, // Directory browser
|
||||||
pub queue_list: Queue, // Stores the current playing queue
|
pub queue_list: ContentList<Song>, // Stores the current playing queue
|
||||||
pub pl_list: ContentList<String>, // Stores list of playlists
|
pub pl_list: ContentList<String>, // Stores list of playlists
|
||||||
pub selected_tab: SelectedTab, // Used to switch between tabs
|
pub selected_tab: SelectedTab, // Used to switch between tabs
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
pub inputmode: InputMode, // Defines input mode, Normal or Search
|
pub inputmode: InputMode, // Defines input mode, Normal or Search
|
||||||
|
|
@ -44,7 +43,7 @@ pub enum SelectedTab {
|
||||||
impl App {
|
impl App {
|
||||||
pub fn builder(addrs: &str) -> AppResult<Self> {
|
pub fn builder(addrs: &str) -> AppResult<Self> {
|
||||||
let mut conn = Connection::new(addrs).unwrap();
|
let mut conn = Connection::new(addrs).unwrap();
|
||||||
let mut queue_list = Queue::new();
|
let mut queue_list = ContentList::new();
|
||||||
let mut pl_list = ContentList::new();
|
let mut pl_list = ContentList::new();
|
||||||
pl_list.list = Self::get_playlist(&mut conn.conn)?;
|
pl_list.list = Self::get_playlist(&mut conn.conn)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,3 @@ pub mod handler;
|
||||||
|
|
||||||
/// Application
|
/// Application
|
||||||
pub mod app;
|
pub mod app;
|
||||||
|
|
||||||
/// The Queue structure
|
|
||||||
pub mod queue;
|
|
||||||
|
|
|
||||||
41
src/queue.rs
41
src/queue.rs
|
|
@ -1,41 +0,0 @@
|
||||||
use mpd::Song;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Queue {
|
|
||||||
pub list: Vec<Song>,
|
|
||||||
pub index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Queue {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Queue {
|
|
||||||
list: Vec::new(),
|
|
||||||
index: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go to next item in list
|
|
||||||
pub fn next(&mut self) {
|
|
||||||
let len = self.list.len();
|
|
||||||
if len != 0 && self.index < len - 1 {
|
|
||||||
self.index += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Go to previous item in list
|
|
||||||
pub fn prev(&mut self) {
|
|
||||||
if self.index != 0 {
|
|
||||||
self.index -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_index(&mut self) {
|
|
||||||
self.index = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Queue {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -362,9 +362,9 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
|
||||||
let table = Table::new(
|
let table = Table::new(
|
||||||
rows,
|
rows,
|
||||||
vec![
|
vec![
|
||||||
Constraint::Min(40),
|
Constraint::Min(48),
|
||||||
Constraint::Percentage(40),
|
Constraint::Percentage(48),
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(4),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.block(title)
|
.block(title)
|
||||||
|
|
|
||||||
Reference in New Issue