rmptui38ebdf9
get rid of humantime crate
+24 −18
5 files changed
- M Cargo.lock +0 −7
- M Cargo.toml +0 −1
- M README.md +1 −1
- M src/app.rs +18 −1
- M src/ui.rs +5 −8
| @@ -225,12 +225,6 @@ version = "0.5.0" | |||
| 225 | 225 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 226 | 226 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" | |
| 227 | 227 | ||
| 228 | − | [[package]] | |
| 229 | − | name = "humantime" | |
| 230 | − | version = "2.1.0" | |
| 231 | − | source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 232 | − | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" | |
| 233 | − | ||
| 234 | 228 | [[package]] | |
| 235 | 229 | name = "indoc" | |
| 236 | 230 | version = "2.0.5" | |
| @@ -392,7 +386,6 @@ version = "0.1.0" | |||
| 392 | 386 | dependencies = [ | |
| 393 | 387 | "clap", | |
| 394 | 388 | "crossterm", | |
| 395 | − | "humantime", | |
| 396 | 389 | "mpd", | |
| 397 | 390 | "ratatui", | |
| 398 | 391 | "rust-fuzzy-search", | |
| @@ -13,4 +13,3 @@ simple-dmenu = "0.1.0" | |||
| 13 | 13 | ratatui = "0.26.2" | |
| 14 | 14 | crossterm = "0.27.0" | |
| 15 | 15 | rust-fuzzy-search = "0.1.1" | |
| 16 | − | humantime = "2.1.0" | |
| @@ -37,7 +37,7 @@ A MPD client in Rust | |||
| 37 | 37 | - [x] improvements on queue control | |
| 38 | 38 | - [x] add to playlists | |
| 39 | 39 | - [x] search for songs | |
| 40 | − | - [x] Humantime format | |
| 40 | + | - [x] Human readable time format | |
| 41 | 41 | - [x] metadata based tree view | |
| 42 | 42 | - [ ] view playlist | |
| 43 | 43 | - [ ] change playlist name | |
| @@ -1,3 +1,5 @@ | |||
| 1 | + | use std::time::Duration; | |
| 2 | + | ||
| 1 | 3 | use crate::browser::FileBrowser; | |
| 2 | 4 | use crate::connection::Connection; | |
| 3 | 5 | use crate::list::ContentList; | |
| @@ -152,7 +154,9 @@ impl App { | |||
| 152 | 154 | for (i, song) in self.queue_list.list.clone().iter().enumerate() { | |
| 153 | 155 | if song.contains(&file) { | |
| 154 | 156 | self.conn.conn.delete(i as u32).unwrap(); | |
| 155 | − | if self.queue_list.index == self.queue_list.list.len() - 1 && self.queue_list.index != 0 { | |
| 157 | + | if self.queue_list.index == self.queue_list.list.len() - 1 | |
| 158 | + | && self.queue_list.index != 0 | |
| 159 | + | { | |
| 156 | 160 | self.queue_list.index -= 1; | |
| 157 | 161 | } | |
| 158 | 162 | } | |
| @@ -268,4 +272,17 @@ impl App { | |||
| 268 | 272 | pub fn reset_cursor(&mut self) { | |
| 269 | 273 | self.cursor_position = 0; | |
| 270 | 274 | } | |
| 275 | + | ||
| 276 | + | /// Given time in seconds, convert it to hh:mm:ss | |
| 277 | + | pub fn format_time(time: Duration) -> String { | |
| 278 | + | let time = time.as_secs(); | |
| 279 | + | let h = time / 3600; | |
| 280 | + | let m = (time % 3600) / 60; | |
| 281 | + | let s = (time % 3600) % 60; | |
| 282 | + | if h == 0 { | |
| 283 | + | format!("{:02}:{:02}", m, s) | |
| 284 | + | } else { | |
| 285 | + | format!("{:02}:{:02}:{:02}", h, m, s) | |
| 286 | + | } | |
| 287 | + | } | |
| 271 | 288 | } | |
| @@ -77,9 +77,8 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 77 | 77 | .collect::<Vec<String>>() | |
| 78 | 78 | .join(""); | |
| 79 | 79 | ||
| 80 | − | let time = humantime::format_duration( | |
| 81 | − | song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)), | |
| 82 | − | ); | |
| 80 | + | let time = | |
| 81 | + | App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0))); | |
| 83 | 82 | ||
| 84 | 83 | let mut status: bool = false; | |
| 85 | 84 | for sn in app.queue_list.list.iter() { | |
| @@ -188,9 +187,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 188 | 187 | .collect::<Vec<String>>() | |
| 189 | 188 | .join(""); | |
| 190 | 189 | ||
| 191 | − | let time = humantime::format_duration( | |
| 192 | − | song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)), | |
| 193 | − | ); | |
| 190 | + | let time = App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0))); | |
| 194 | 191 | ||
| 195 | 192 | if s.contains(&app.conn.current_song.file) { | |
| 196 | 193 | let row = Row::new(vec![ | |
| @@ -353,8 +350,8 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 353 | 350 | let duration = if app.conn.total_duration.as_secs() != 0 { | |
| 354 | 351 | format!( | |
| 355 | 352 | "[{}/{}]", | |
| 356 | − | humantime::format_duration(app.conn.elapsed), | |
| 357 | − | humantime::format_duration(app.conn.total_duration) | |
| 353 | + | App::format_time(app.conn.elapsed), | |
| 354 | + | App::format_time(app.conn.total_duration) | |
| 358 | 355 | ) | |
| 359 | 356 | } else { | |
| 360 | 357 | "".to_string() | |