Unnamed repository; edit this file 'description' to name the repository.
use human-readable sizes for file size on save/write (#13627)
Saheed Adeleye 8 months ago
parent fba644f · commit e11794b
-rw-r--r--helix-term/src/application.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index eadda721..2b2ff855 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -569,16 +569,24 @@ impl Application {
doc.set_last_saved_revision(doc_save_event.revision, doc_save_event.save_time);
let lines = doc_save_event.text.len_lines();
- let bytes = doc_save_event.text.len_bytes();
+ let mut sz = doc_save_event.text.len_bytes() as f32;
+
+ const SUFFIX: [&str; 4] = ["B", "KiB", "MiB", "GiB"];
+ let mut i = 0;
+ while i < SUFFIX.len() - 1 && sz >= 1024.0 {
+ sz /= 1024.0;
+ i += 1;
+ }
self.editor
.set_doc_path(doc_save_event.doc_id, &doc_save_event.path);
// TODO: fix being overwritten by lsp
self.editor.set_status(format!(
- "'{}' written, {}L {}B",
+ "'{}' written, {}L {:.1}{}",
get_relative_path(&doc_save_event.path).to_string_lossy(),
lines,
- bytes
+ sz,
+ SUFFIX[i],
));
}