summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-21 11:35:46 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-21 11:35:46 -0400
commite1998c81383a6929bff21a17ac08c16eea0e945a (patch)
tree51db2592f5fe8c3b23a9cf911f36fcae01325b5d /src
parent8fc59f0a0c3729d201f844738db5275035f59f2d (diff)
format bytes into KB, MB, etc
Diffstat (limited to 'src')
-rw-r--r--src/run.rs15
-rw-r--r--src/ui/widgets/tui_dirlist_detailed.rs2
-rw-r--r--src/ui/widgets/tui_footer.rs2
-rw-r--r--src/util/format.rs3
4 files changed, 13 insertions, 9 deletions
diff --git a/src/run.rs b/src/run.rs
index 928b708..65f52c8 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -7,6 +7,7 @@ use crate::tab::JoshutoTab;
use crate::ui;
use crate::ui::widgets::{TuiCommandMenu, TuiView};
use crate::util::event::Event;
+use crate::util::format;
use crate::util::load_child::LoadChild;
pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io::Result<()> {
@@ -58,17 +59,19 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io:
let dest = handle.dest.clone();
handle.join();
let msg = match res {
- Ok(s) => format!(
- "io_worker completed successfully: {:.3} KB processed",
- s as f64 / 1024.0
- ),
+ Ok(s) => {
+ let size_string = format::file_size_to_string(s);
+ format!(
+ "io_worker completed successfully: {} processed",
+ size_string)
+ }
Err(e) => format!("io_worker was not completed: {}", e.to_string()),
};
context.message_queue.push_back(msg);
let options = &context.config_t.sort_option;
for tab in context.tabs.iter_mut() {
- tab.history.reload(&src, options);
- tab.history.reload(&dest, options);
+ tab.history.reload(&src, options)?;
+ tab.history.reload(&dest, options)?;
}
LoadChild::load_child(&mut context)?;
}
diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs
index 08c6f80..5ec8633 100644
--- a/src/ui/widgets/tui_dirlist_detailed.rs
+++ b/src/ui/widgets/tui_dirlist_detailed.rs
@@ -96,7 +96,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
}
}
}
- let file_size_string = format::file_size_to_string(entry.metadata.len as f64);
+ let file_size_string = format::file_size_to_string(entry.metadata.len);
buf.set_string(
x + (area_width - FILE_SIZE_WIDTH) as u16,
y + i as u16,
diff --git a/src/ui/widgets/tui_footer.rs b/src/ui/widgets/tui_footer.rs
index 072b143..e957590 100644
--- a/src/ui/widgets/tui_footer.rs
+++ b/src/ui/widgets/tui_footer.rs
@@ -31,7 +31,7 @@ impl<'a> Widget for TuiFooter<'a> {
let mtime = format::mtime_to_string(mtime);
let size = self.entry.metadata.len;
- let size = format::file_size_to_string(size as f64);
+ let size = format::file_size_to_string(size);
#[cfg(unix)]
let mimetype = match self.entry.metadata.mimetype.as_ref() {
diff --git a/src/util/format.rs b/src/util/format.rs
index 53fbf5f..7c0e23f 100644
--- a/src/util/format.rs
+++ b/src/util/format.rs
@@ -2,9 +2,10 @@ use std::time;
use super::unix;
-pub fn file_size_to_string(mut file_size: f64) -> String {
+pub fn file_size_to_string(mut file_size: u64) -> String {
const FILE_UNITS: [&str; 6] = ["B", "K", "M", "G", "T", "E"];
const CONV_RATE: f64 = 1024.0;
+ let mut file_size: f64 = file_size as f64;
let mut index = 0;
while file_size > CONV_RATE {