diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-03-09 00:19:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 00:19:02 +0100 |
commit | 22dbbf75f36315d4a203011ff9e37c7e56a7bef0 (patch) | |
tree | 274410d1935ec35ca34d693363c049701e0b8c11 /cli/main.rs | |
parent | a3d6be025c14174ce6e270a3004b9892d5aae071 (diff) |
refactor: add cli/display.rs module (#13879)
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/cli/main.rs b/cli/main.rs index 1bbc839e8..8d0a7a2ba 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -10,6 +10,7 @@ mod deno_dir; mod diagnostics; mod diff; mod disk_cache; +mod display; mod emit; mod errors; mod file_fetcher; @@ -755,28 +756,6 @@ fn bundle_module_graph( ) } -/// A function that converts a float to a string the represents a human -/// readable version of that number. -fn human_size(size: f64) -> String { - let negative = if size.is_sign_positive() { "" } else { "-" }; - let size = size.abs(); - let units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; - if size < 1_f64 { - return format!("{}{}{}", negative, size, "B"); - } - let delimiter = 1024_f64; - let exponent = std::cmp::min( - (size.ln() / delimiter.ln()).floor() as i32, - (units.len() - 1) as i32, - ); - let pretty_bytes = format!("{:.2}", size / delimiter.powi(exponent)) - .parse::<f64>() - .unwrap() - * 1_f64; - let unit = units[exponent as usize]; - format!("{}{}{}", negative, pretty_bytes, unit) -} - async fn bundle_command( flags: Flags, bundle_flags: BundleFlags, @@ -843,7 +822,7 @@ async fn bundle_command( "{} {:?} ({})", colors::green("Emit"), out_file, - colors::gray(human_size(output_len as f64)) + colors::gray(display::human_size(output_len as f64)) ); if let Some(bundle_map) = maybe_bundle_map { let map_bytes = bundle_map.as_bytes(); @@ -859,7 +838,7 @@ async fn bundle_command( "{} {:?} ({})", colors::green("Emit"), map_out_file, - colors::gray(human_size(map_len as f64)) + colors::gray(display::human_size(map_len as f64)) ); } } else { |