Krolyxon
Commit bf11d59

rmptuibf11d59

hmm stuff

Author
krolxon
Date
2024-04-24 12:36 +0530
Parent
b93eae4
Commit
bf11d5967fd52453292e8a5a0d9a0c618a03c4ad

+62 −47

4 files changed

  1. M src/app.rs +11 −10
  2. M src/connection.rs +1 −1
  3. M src/handler.rs +21 −12
  4. M src/ui.rs +29 −24
M src/app.rs View
@@ -12,7 +12,7 @@ pub struct App {
1212 /// check if app is running
1313 pub running: bool,
1414 pub conn: Connection,
15− pub play_deque: VecDeque<String>,
15+ pub play_deque: ContentList<String>,
1616 pub song_list: ContentList<String>,
1717 pub queue_list: ContentList<String>,
1818 pub pl_list: ContentList<String>,
@@ -21,10 +21,11 @@ pub struct App {
2121 impl App {
2222 pub fn builder(addrs: &str) -> AppResult<Self> {
2323 let mut conn = Connection::new(addrs).unwrap();
24− let mut vec: VecDeque<String> = VecDeque::new();
24+ let mut queue = ContentList::new();
2525 let mut pl_list = ContentList::new();
2626 pl_list.list = Self::get_playlist(&mut conn.conn)?;
27− Self::get_queue(&mut conn, &mut vec);
27+
28+ Self::get_queue(&mut conn, &mut queue.list);
2829
2930 let mut song_list = ContentList::new();
3031 song_list.list = conn.songs_filenames.clone();
@@ -32,7 +33,7 @@ impl App {
3233 Ok(Self {
3334 running: true,
3435 conn,
35− play_deque: vec,
36+ play_deque: ContentList::new(),
3637 song_list,
3738 queue_list: ContentList::new(),
3839 pl_list,
@@ -45,23 +46,23 @@ impl App {
4546 self.running = false;
4647 }
4748
48− pub fn get_queue(conn: &mut Connection, vec: &mut VecDeque<String>) {
49+ pub fn get_queue(conn: &mut Connection, vec: &mut Vec<String>) {
4950 conn.conn.queue().unwrap().into_iter().for_each(|x| {
5051 if let Some(title) = x.title {
5152 if let Some(artist) = x.artist {
52− vec.push_back(format!("{} - {}", artist, title));
53+ vec.push(format!("{} - {}", artist, title));
5354 } else {
54− vec.push_back(title)
55+ vec.push(title)
5556 }
5657 } else {
57− vec.push_back(x.file)
58+ vec.push(x.file)
5859 }
5960 });
6061 }
6162
6263 pub fn update_queue(&mut self) {
63− self.play_deque.clear();
64− Self::get_queue(&mut self.conn, &mut self.play_deque);
64+ self.queue_list.list.clear();
65+ Self::get_queue(&mut self.conn, &mut self.queue_list.list);
6566 }
6667
6768 pub fn get_playlist(conn: &mut Client) -> AppResult<Vec<String>> {
M src/connection.rs View
@@ -132,7 +132,7 @@ impl Connection {
132132
133133 /// Gives title of current playing song
134134 pub fn now_playing(&mut self) -> Result<Option<String>> {
135− let song = self.conn.currentsong()?.unwrap();
135+ let song = self.conn.currentsong()?.unwrap_or_default();
136136 if let Some(s) = song.title {
137137 if let Some(a) = song.artist {
138138 return Ok(Some(format!("{} - {}", s, a)));
M src/handler.rs View
@@ -19,7 +19,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
1919 }
2020
2121 KeyCode::Enter | KeyCode::Char('l') => {
22− let song = app.conn.get_song_with_only_filename(app.conn.songs_filenames.get(app.song_list.index).unwrap());
22+ let song = app.conn.get_song_with_only_filename(
23+ app.conn.songs_filenames.get(app.song_list.index).unwrap(),
24+ );
2325 app.conn.push(&song)?;
2426 // app.update_queue();
2527 }
@@ -35,7 +37,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
3537 app.conn.pause();
3638 }
3739
38−
3940 // Clearn Queue
4041 KeyCode::Char('x') => {
4142 app.conn.conn.clear()?;
@@ -46,31 +47,39 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
4647 app.conn.play_dmenu()?;
4748 }
4849
49− KeyCode::Down=> {
50− app.pl_list.next();
50+ KeyCode::Down => {
51+ if key_event.modifiers == KeyModifiers::SHIFT {
52+ app.queue_list.next();
53+ } else {
54+ app.pl_list.next();
55+ }
5156 }
5257
53− KeyCode::Up=> {
54− app.pl_list.prev();
58+ KeyCode::Up => {
59+ if key_event.modifiers == KeyModifiers::SHIFT {
60+ app.queue_list.prev();
61+ } else {
62+ app.pl_list.prev();
63+ }
5564 }
5665
57−
5866 KeyCode::Right => {
59− app.conn.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
67+ app.conn
68+ .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
6069 }
6170
62− KeyCode::Char('f')=> {
71+ KeyCode::Char('f') => {
6372 // let place = app.conn.conn.status().unwrap().duration;
6473 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
6574 let pos: i64 = (pos.as_secs() + 2).try_into().unwrap();
66− app.conn.conn.seek(2, pos )?;
75+ app.conn.conn.seek(2, pos)?;
6776 }
6877
69− KeyCode::Char('b')=> {
78+ KeyCode::Char('b') => {
7079 // let place = app.conn.conn.status().unwrap().duration;
7180 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
7281 let pos: i64 = (pos.as_secs() - 2).try_into().unwrap();
73− app.conn.conn.seek(2, pos )?;
82+ app.conn.conn.seek(2, pos)?;
7483 }
7584 _ => {}
7685 }
M src/ui.rs View
@@ -1,5 +1,5 @@
11 use crate::app::{App, AppResult};
2−use ratatui::{prelude::*, widgets::*};
2+use ratatui::{prelude::*, widgets::{block::Title, *}};
33
44 /// Renders the user interface widgets
55 pub fn render(app: &mut App, frame: &mut Frame) {
@@ -29,32 +29,33 @@ pub fn render(app: &mut App, frame: &mut Frame) {
2929 draw_playlists(frame, app, inner_layout[1]);
3030
3131 // Status
32− // let song = app
33− // .conn
34− // .now_playing().unwrap()
35− // .unwrap_or_else(|| "No Title Found".to_string());
36− //
37− // let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap();
38− //
39− // let mut lines = vec![];
40− // lines.push(Line::from(vec![
41− // Span::styled("Current: ", Style::default().fg(Color::Red)),
42− // Span::styled(song, Style::default().fg(Color::Yellow)),
43− // Span::styled(
44− // format!("[{}/{}]", elapsed.as_secs(), total.as_secs()),
45− // Style::default().fg(Color::Yellow),
46− // ),
47− // ]));
48− // let status = Paragraph::new(Text::from(lines))
49− // .block(Block::default().title("Status").borders(Borders::ALL));
50− // frame.render_widget(status, main_layout[1]);
32+ let song = app
33+ .conn
34+ .now_playing().unwrap()
35+ .unwrap_or_else(|| "No Title Found".to_string());
36+
37+ let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap_or_default();
38+
39+ let mut lines = vec![];
40+ lines.push(Line::from(vec![
41+ Span::styled("Current: ", Style::default().fg(Color::Red)),
42+ Span::styled(song, Style::default().fg(Color::Yellow)),
43+ Span::styled(
44+ format!("[{}/{}]", elapsed.as_secs(), total.as_secs()),
45+ Style::default().fg(Color::Yellow),
46+ ),
47+ ]));
48+ let status = Paragraph::new(Text::from(lines))
49+ .block(Block::default().title("Status".bold().green()).borders(Borders::ALL));
50+ frame.render_widget(status, main_layout[1]);
51+
5152 }
5253
5354 /// draws list of songs
5455 fn draw_song_list(frame: &mut Frame, app: &mut App, size: Rect) {
5556 let mut song_state = ListState::default();
5657 let list = List::new(app.conn.songs_filenames.clone())
57− .block(Block::default().title("Song List").borders(Borders::ALL))
58+ .block(Block::default().title("Song List".green().bold()).borders(Borders::ALL))
5859 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
5960 .highlight_symbol(">>")
6061 .repeat_highlight_symbol(true);
@@ -66,21 +67,25 @@ fn draw_song_list(frame: &mut Frame, app: &mut App, size: Rect) {
6667 /// draws playing queue
6768 fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
6869 let mut queue_state = ListState::default();
69− let list = List::new(app.play_deque.clone())
70− .block(Block::default().title("Play Queue").borders(Borders::ALL))
70+ let title = Block::default().title(Title::from("Play Queue".green().bold())).title("Shift + ▲ ▼ to scroll, Shift + Enter to play".yellow());
71+ let list = List::new(app.queue_list.list.clone())
72+ .block(title.borders(Borders::ALL))
7173 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
7274 .highlight_symbol(">>")
7375 .repeat_highlight_symbol(true);
7476
7577 app.update_queue();
78+ queue_state.select(Some(app.queue_list.index));
7679 frame.render_stateful_widget(list, size, &mut queue_state);
7780 }
7881
7982 /// draws all playlists
8083 fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) {
8184 let mut state = ListState::default();
85+
86+ let title = Block::default().title(Title::from("Playlist".green().bold())).title("▲ ▼ to scroll, Use ► to add playlist to queue".yellow());
8287 let list = List::new(app.pl_list.list.clone())
83− .block(Block::default().title("Playlists").borders(Borders::ALL))
88+ .block(title.borders(Borders::ALL))
8489 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
8590 .highlight_symbol(">>")
8691 .repeat_highlight_symbol(true);