From 7aa5f18b41bbd4e5a7d143c67d80943e87e09f63 Mon Sep 17 00:00:00 2001 From: Seno Pamungkas Date: Fri, 29 Aug 2025 15:05:58 +0700 Subject: [PATCH] feat: progression status for copy I/O in Tasks window --- yazi-shared/src/bytes.rs | 16 ++++++++++++++++ yazi-shared/src/url/buf.rs | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/yazi-shared/src/bytes.rs b/yazi-shared/src/bytes.rs index aedcb47f..7c899c1c 100644 --- a/yazi-shared/src/bytes.rs +++ b/yazi-shared/src/bytes.rs @@ -9,3 +9,19 @@ impl BytesExt for [u8] { Some((left, &right[sep.len()..])) } } + +pub fn human_bytes(n: u64) -> String { + const KB: f64 = 1024.0; + const MB: f64 = KB * 1024.0; + const GB: f64 = MB * 1024.0; + let x = n as f64; + if x >= GB { + format!("{:.2} GB", x / GB) + } else if x >= MB { + format!("{:.2} MB", x / MB) + } else if x >= KB { + format!("{:.2} KB", x / KB) + } else { + format!("{n} B") + } +} diff --git a/yazi-shared/src/url/buf.rs b/yazi-shared/src/url/buf.rs index 13e4a4c0..e72ee1d4 100644 --- a/yazi-shared/src/url/buf.rs +++ b/yazi-shared/src/url/buf.rs @@ -339,7 +339,7 @@ mod tests { for (path, expected) in cases { let path: UrlBuf = path.parse()?; - assert_eq!(path.parent().map(|u| format!("{:?}", u)).as_deref(), expected); + assert_eq!(path.parent().map(|u| format!("{u:?}")).as_deref(), expected); } Ok(())