From d1d2fae13d23b50b99dfc4fca98863ce5362f29e Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Wed, 29 May 2019 21:43:16 +0800 Subject: [PATCH] Prettify top capacity page --- src/subcommands/tui/mod.rs | 8 ++++++-- src/subcommands/tui/util.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/subcommands/tui/mod.rs b/src/subcommands/tui/mod.rs index 9a43a52b..643422fc 100644 --- a/src/subcommands/tui/mod.rs +++ b/src/subcommands/tui/mod.rs @@ -24,7 +24,7 @@ use ckb_core::service::Request; use super::wallet::{IndexController, IndexRequest, IndexResponse}; use crate::utils::printer::Printable; use state::{start_rpc_thread, State, SummaryInfo}; -use util::{ts_now, App, Event, Events, TabsState}; +use util::{human_capacity, ts_now, App, Event, Events, TabsState}; use widgets::List; pub struct TuiSubCommand { @@ -464,7 +464,11 @@ fn render_top_capacity(index: &IndexController, ctx: RenderContext u64 { .as_millis() as u64 } +pub fn human_capacity(value: u64) -> String { + let value_f64 = value as f64 / 10000.0 / 10000.0; + if value_f64 >= (1024.0 * 1024.0) { + format!("{:.2}MCKB", value_f64 / 1024.0 / 1024.0) + } else if value_f64 >= 1024.0 { + format!("{:.2}KCKB", value_f64 / 1024.0) + } else { + format!("{:.1}CKB", value_f64) + } +} + pub struct App { pub(crate) menu_active: bool, pub(crate) tabs: TabsState,