diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/app.rs | 19 | ||||
| -rwxr-xr-x | src/ui.rs | 13 |
2 files changed, 23 insertions, 9 deletions
@@ -1,3 +1,5 @@ +use std::time::Duration; + use crate::browser::FileBrowser; use crate::connection::Connection; use crate::list::ContentList; @@ -152,7 +154,9 @@ impl App { for (i, song) in self.queue_list.list.clone().iter().enumerate() { if song.contains(&file) { self.conn.conn.delete(i as u32).unwrap(); - if self.queue_list.index == self.queue_list.list.len() - 1 && self.queue_list.index != 0 { + if self.queue_list.index == self.queue_list.list.len() - 1 + && self.queue_list.index != 0 + { self.queue_list.index -= 1; } } @@ -268,4 +272,17 @@ impl App { pub fn reset_cursor(&mut self) { self.cursor_position = 0; } + + /// Given time in seconds, convert it to hh:mm:ss + pub fn format_time(time: Duration) -> String { + let time = time.as_secs(); + let h = time / 3600; + let m = (time % 3600) / 60; + let s = (time % 3600) % 60; + if h == 0 { + format!("{:02}:{:02}", m, s) + } else { + format!("{:02}:{:02}:{:02}", h, m, s) + } + } } @@ -77,9 +77,8 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { .collect::<Vec<String>>() .join(""); - let time = humantime::format_duration( - song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)), - ); + let time = + App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0))); let mut status: bool = false; for sn in app.queue_list.list.iter() { @@ -188,9 +187,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { .collect::<Vec<String>>() .join(""); - let time = humantime::format_duration( - song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)), - ); + let time = App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0))); if s.contains(&app.conn.current_song.file) { let row = Row::new(vec![ @@ -353,8 +350,8 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { let duration = if app.conn.total_duration.as_secs() != 0 { format!( "[{}/{}]", - humantime::format_duration(app.conn.elapsed), - humantime::format_duration(app.conn.total_duration) + App::format_time(app.conn.elapsed), + App::format_time(app.conn.total_duration) ) } else { "".to_string() |
