get rid of humantime crate

This commit is contained in:
krolxon 2024-04-29 17:24:49 +05:30
parent 11d6472874
commit 38ebdf9283
5 changed files with 24 additions and 18 deletions

7
Cargo.lock generated
View File

@ -225,12 +225,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "indoc" name = "indoc"
version = "2.0.5" version = "2.0.5"
@ -392,7 +386,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"crossterm", "crossterm",
"humantime",
"mpd", "mpd",
"ratatui", "ratatui",
"rust-fuzzy-search", "rust-fuzzy-search",

View File

@ -13,4 +13,3 @@ simple-dmenu = "0.1.0"
ratatui = "0.26.2" ratatui = "0.26.2"
crossterm = "0.27.0" crossterm = "0.27.0"
rust-fuzzy-search = "0.1.1" rust-fuzzy-search = "0.1.1"
humantime = "2.1.0"

View File

@ -37,7 +37,7 @@ A MPD client in Rust
- [x] improvements on queue control - [x] improvements on queue control
- [x] add to playlists - [x] add to playlists
- [x] search for songs - [x] search for songs
- [x] Humantime format - [x] Human readable time format
- [x] metadata based tree view - [x] metadata based tree view
- [ ] view playlist - [ ] view playlist
- [ ] change playlist name - [ ] change playlist name

View File

@ -1,3 +1,5 @@
use std::time::Duration;
use crate::browser::FileBrowser; use crate::browser::FileBrowser;
use crate::connection::Connection; use crate::connection::Connection;
use crate::list::ContentList; use crate::list::ContentList;
@ -152,7 +154,9 @@ impl App {
for (i, song) in self.queue_list.list.clone().iter().enumerate() { for (i, song) in self.queue_list.list.clone().iter().enumerate() {
if song.contains(&file) { if song.contains(&file) {
self.conn.conn.delete(i as u32).unwrap(); 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; self.queue_list.index -= 1;
} }
} }
@ -268,4 +272,17 @@ impl App {
pub fn reset_cursor(&mut self) { pub fn reset_cursor(&mut self) {
self.cursor_position = 0; 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)
}
}
} }

View File

@ -77,9 +77,8 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(""); .join("");
let time = humantime::format_duration( let time =
song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)), App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)));
);
let mut status: bool = false; let mut status: bool = false;
for sn in app.queue_list.list.iter() { 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>>() .collect::<Vec<String>>()
.join(""); .join("");
let time = humantime::format_duration( let time = App::format_time(song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)));
song.clone().duration.unwrap_or_else(|| Duration::new(0, 0)),
);
if s.contains(&app.conn.current_song.file) { if s.contains(&app.conn.current_song.file) {
let row = Row::new(vec![ 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 { let duration = if app.conn.total_duration.as_secs() != 0 {
format!( format!(
"[{}/{}]", "[{}/{}]",
humantime::format_duration(app.conn.elapsed), App::format_time(app.conn.elapsed),
humantime::format_duration(app.conn.total_duration) App::format_time(app.conn.total_duration)
) )
} else { } else {
"".to_string() "".to_string()