diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-11-17 21:35:15 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-11-17 21:35:15 +0100 |
commit | 3c7eec8920157a1aa3b00fbbbad4786023005ed2 (patch) | |
tree | 21631c53862719a95c4c49c067330f127b2f95d6 | |
parent | 47686209158824bee1aa3c48a82a112818209166 (diff) |
display sum of file size
-rw-r--r-- | src/display.rs | 8 | ||||
-rw-r--r-- | src/fileinfo.rs | 6 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/display.rs b/src/display.rs index 9e09afe..c5fabbe 100644 --- a/src/display.rs +++ b/src/display.rs @@ -7,7 +7,7 @@ use tuikit::term::Term; use crate::config::Colors; use crate::content_window::ContentWindow; -use crate::fileinfo::fileinfo_attr; +use crate::fileinfo::{fileinfo_attr, human_size}; use crate::fm_error::{FmError, FmResult}; use crate::git::git; use crate::last_edition::LastEdition; @@ -90,14 +90,14 @@ impl Display { let tab = status.selected_non_mut(); let first_row: String = match tab.mode { Mode::Normal => { - let git_string = git(&tab.path_content.path)?; format!( - "Tab: {}/{} -- Path: {} -- Files: {} -- {}", + "Tab: {}/{} -- Path: {} -- Files: {} -- Sum: {} -- {}", status.index + 1, status.len(), tab.path_content.path_to_str()?, tab.path_content.files.len(), - git_string, + human_size(tab.path_content.used_space), + git(&tab.path_content.path)?, ) } Mode::NeedConfirmation => { diff --git a/src/fileinfo.rs b/src/fileinfo.rs index 72d1892..389cf18 100644 --- a/src/fileinfo.rs +++ b/src/fileinfo.rs @@ -4,6 +4,7 @@ use std::path; use chrono::offset::Local; use chrono::DateTime; +use fs_extra::dir::get_size; use tuikit::prelude::{Attr, Color, Effect}; use users::get_user_by_uid; @@ -229,6 +230,7 @@ pub struct PathContent { pub sort_by: SortBy, pub reverse: bool, filter: FilterKind, + pub used_space: u64, } impl PathContent { @@ -245,6 +247,7 @@ impl PathContent { files[selected].select(); } let reverse = false; + let used_space = get_size(&path)?; Ok(Self { path, @@ -254,6 +257,7 @@ impl PathContent { sort_by, reverse, filter, + used_space, }) } @@ -483,7 +487,7 @@ fn extract_file_size(direntry: &DirEntry) -> Result<u64, FmError> { } /// Convert a file size from bytes to human readable string. -fn human_size(bytes: u64) -> String { +pub fn human_size(bytes: u64) -> String { let size = ["", "k", "M", "G", "T", "P", "E", "Z", "Y"]; let factor = (bytes.to_string().chars().count() as u64 - 1) / 3_u64; format!( |