use filenames in queue instead of title
This commit is contained in:
parent
9e2b51c8e6
commit
4bc03ce8f4
27
src/app.rs
27
src/app.rs
|
|
@ -17,7 +17,6 @@ pub struct App {
|
||||||
pub selected_tab: SelectedTab,
|
pub selected_tab: SelectedTab,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum SelectedTab {
|
pub enum SelectedTab {
|
||||||
SongList,
|
SongList,
|
||||||
|
|
@ -64,17 +63,21 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_queue(conn: &mut Connection, vec: &mut Vec<String>) {
|
pub fn get_queue(conn: &mut Connection, vec: &mut Vec<String>) {
|
||||||
|
// conn.conn.queue().unwrap().into_iter().for_each(|x| {
|
||||||
|
// if let Some(title) = x.title {
|
||||||
|
// if let Some(artist) = x.artist {
|
||||||
|
// vec.push(format!("{} - {}", artist, title));
|
||||||
|
// } else {
|
||||||
|
// vec.push(title)
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// vec.push(x.file)
|
||||||
|
// }
|
||||||
|
// });
|
||||||
conn.conn.queue().unwrap().into_iter().for_each(|x| {
|
conn.conn.queue().unwrap().into_iter().for_each(|x| {
|
||||||
if let Some(title) = x.title {
|
vec.push(x.file);
|
||||||
if let Some(artist) = x.artist {
|
}
|
||||||
vec.push(format!("{} - {}", artist, title));
|
);
|
||||||
} else {
|
|
||||||
vec.push(title)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vec.push(x.file)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_queue(&mut self) {
|
pub fn update_queue(&mut self) {
|
||||||
|
|
@ -97,7 +100,7 @@ impl App {
|
||||||
self.selected_tab = match self.selected_tab {
|
self.selected_tab = match self.selected_tab {
|
||||||
SelectedTab::SongList => SelectedTab::Queue,
|
SelectedTab::SongList => SelectedTab::Queue,
|
||||||
SelectedTab::Queue => SelectedTab::Playlists,
|
SelectedTab::Queue => SelectedTab::Playlists,
|
||||||
SelectedTab::Playlists=> SelectedTab::SongList,
|
SelectedTab::Playlists => SelectedTab::SongList,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Connection {
|
||||||
pub fn play_dmenu(&mut self) -> Result<()> {
|
pub fn play_dmenu(&mut self) -> Result<()> {
|
||||||
is_installed("dmenu").map_err(|ex| ex)?;
|
is_installed("dmenu").map_err(|ex| ex)?;
|
||||||
let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect();
|
let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect();
|
||||||
let op = dmenu!(iter &ss; args "-l", "30");
|
let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30");
|
||||||
let index = get_choice_index(&self.songs_filenames, &op);
|
let index = get_choice_index(&self.songs_filenames, &op);
|
||||||
let song = self.get_song_with_only_filename(ss.get(index).unwrap());
|
let song = self.get_song_with_only_filename(ss.get(index).unwrap());
|
||||||
self.push(&song)?;
|
self.push(&song)?;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ use std::time::Duration;
|
||||||
|
|
||||||
use crate::app::{App, AppResult, SelectedTab};
|
use crate::app::{App, AppResult, SelectedTab};
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
use ratatui::style::Modifier;
|
|
||||||
|
|
||||||
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
|
@ -35,7 +34,13 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
);
|
);
|
||||||
app.conn.push(&song)?;
|
app.conn.push(&song)?;
|
||||||
}
|
}
|
||||||
SelectedTab::Queue => {}
|
SelectedTab::Queue => {
|
||||||
|
let song = app.conn.get_song_with_only_filename(
|
||||||
|
app.queue_list.list.get(app.queue_list.index).unwrap(),
|
||||||
|
);
|
||||||
|
app.conn.push(&song)?;
|
||||||
|
|
||||||
|
}
|
||||||
SelectedTab::Playlists => {
|
SelectedTab::Playlists => {
|
||||||
app.conn
|
app.conn
|
||||||
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
|
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
|
||||||
|
|
@ -63,10 +68,21 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
// app.update_queue();
|
// app.update_queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyCode::Char('d') => {
|
// Dmenu prompt
|
||||||
|
KeyCode::Char('D') => {
|
||||||
app.conn.play_dmenu()?;
|
app.conn.play_dmenu()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add to queue
|
||||||
|
KeyCode::Char('a') => {
|
||||||
|
let song = app.conn.get_song_with_only_filename(
|
||||||
|
app.conn.songs_filenames.get(app.song_list.index).unwrap(),
|
||||||
|
);
|
||||||
|
app.conn.conn.push(&song)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyCode::Right => {
|
KeyCode::Right => {
|
||||||
app.conn
|
app.conn
|
||||||
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
|
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
|
||||||
|
|
@ -102,13 +118,12 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
app.selected_tab = SelectedTab::Playlists;
|
app.selected_tab = SelectedTab::Playlists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyCode::Char('n') => {
|
KeyCode::Char('n') => {
|
||||||
app.conn.conn.next()?;
|
app.conn.conn.next()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyCode::Char('N') => {
|
KeyCode::Char('N') => {
|
||||||
app.conn.conn.prev()?;
|
app.conn.conn.prev()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volume controls
|
// Volume controls
|
||||||
|
|
@ -120,7 +135,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
app.conn.dec_volume(2);
|
app.conn.dec_volume(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete highlighted song from the queue
|
||||||
|
KeyCode::Char('d') => {
|
||||||
|
app.conn.conn.delete(app.queue_list.index as u32)?;
|
||||||
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue