| @@ -1,5 +1,8 @@ |
| 1 | 1 | | use crate::app::{App, AppResult}; |
| 2 | | − | use ratatui::{prelude::*, widgets::{block::Title, *}}; |
| 2 | + | use ratatui::{ |
| 3 | + | prelude::*, |
| 4 | + | widgets::{block::Title, *}, |
| 5 | + | }; |
| 3 | 6 | | |
| 4 | 7 | | /// Renders the user interface widgets |
| 5 | 8 | | pub fn render(app: &mut App, frame: &mut Frame) { |
| @@ -27,35 +30,18 @@ pub fn render(app: &mut App, frame: &mut Frame) { |
| 27 | 30 | | draw_song_list(frame, app, outer_layout[0]); |
| 28 | 31 | | draw_queue(frame, app, inner_layout[0]); |
| 29 | 32 | | draw_playlists(frame, app, inner_layout[1]); |
| 30 | | − | |
| 31 | | − | // 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_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 | | − | |
| 33 | + | draw_progress_bar(frame, app, main_layout[1]); |
| 52 | 34 | | } |
| 53 | 35 | | |
| 54 | 36 | | /// draws list of songs |
| 55 | 37 | | fn draw_song_list(frame: &mut Frame, app: &mut App, size: Rect) { |
| 56 | 38 | | let mut song_state = ListState::default(); |
| 57 | 39 | | let list = List::new(app.conn.songs_filenames.clone()) |
| 58 | | − | .block(Block::default().title("Song List".green().bold()).borders(Borders::ALL)) |
| 40 | + | .block( |
| 41 | + | Block::default() |
| 42 | + | .title("Song List".green().bold()) |
| 43 | + | .borders(Borders::ALL), |
| 44 | + | ) |
| 59 | 45 | | .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) |
| 60 | 46 | | .highlight_symbol(">>") |
| 61 | 47 | | .repeat_highlight_symbol(true); |
| @@ -67,7 +53,9 @@ fn draw_song_list(frame: &mut Frame, app: &mut App, size: Rect) { |
| 67 | 53 | | /// draws playing queue |
| 68 | 54 | | fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { |
| 69 | 55 | | let mut queue_state = ListState::default(); |
| 70 | | − | let title = Block::default().title(Title::from("Play Queue".green().bold())).title("Shift + ▲ ▼ to scroll, Shift + Enter to play".yellow()); |
| 56 | + | let title = Block::default() |
| 57 | + | .title(Title::from("Play Queue".green().bold())) |
| 58 | + | .title("Shift + ▲ ▼ to scroll, Shift + Enter to play".yellow()); |
| 71 | 59 | | let list = List::new(app.queue_list.list.clone()) |
| 72 | 60 | | .block(title.borders(Borders::ALL)) |
| 73 | 61 | | .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) |
| @@ -83,7 +71,9 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { |
| 83 | 71 | | fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) { |
| 84 | 72 | | let mut state = ListState::default(); |
| 85 | 73 | | |
| 86 | | − | let title = Block::default().title(Title::from("Playlist".green().bold())).title("▲ ▼ to scroll, Use ► to add playlist to queue".yellow()); |
| 74 | + | let title = Block::default() |
| 75 | + | .title(Title::from("Playlist".green().bold())) |
| 76 | + | .title("▲ ▼ to scroll, Use ► to add playlist to queue".yellow()); |
| 87 | 77 | | let list = List::new(app.pl_list.list.clone()) |
| 88 | 78 | | .block(title.borders(Borders::ALL)) |
| 89 | 79 | | .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) |
| @@ -93,3 +83,31 @@ fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) { |
| 93 | 83 | | state.select(Some(app.pl_list.index)); |
| 94 | 84 | | frame.render_stateful_widget(list, size, &mut state); |
| 95 | 85 | | } |
| 86 | + | |
| 87 | + | // Progress Bar |
| 88 | + | fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { |
| 89 | + | let song = app |
| 90 | + | .conn |
| 91 | + | .now_playing() |
| 92 | + | .unwrap() |
| 93 | + | .unwrap_or_else(|| "No Title Found".to_string()); |
| 94 | + | |
| 95 | + | let state = &app.conn.state; |
| 96 | + | // let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap_or_default(); |
| 97 | + | |
| 98 | + | let title = Block::default() |
| 99 | + | .title(Title::from(format!("{}: ", state).red().bold())) |
| 100 | + | .title(Title::from(song.green().bold())); |
| 101 | + | let progress_bar = LineGauge::default() |
| 102 | + | .block(title.borders(Borders::ALL)) |
| 103 | + | .gauge_style( |
| 104 | + | Style::default() |
| 105 | + | .fg(Color::LightBlue) |
| 106 | + | .bg(Color::Gray) |
| 107 | + | .add_modifier(Modifier::BOLD), |
| 108 | + | ) |
| 109 | + | .line_set(symbols::line::THICK) |
| 110 | + | .ratio(0.2); |
| 111 | + | |
| 112 | + | frame.render_widget(progress_bar, size); |
| 113 | + | } |