Skip to content

Commit

Permalink
Prettify top capacity page
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed May 29, 2019
1 parent d0312b0 commit d1d2fae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/subcommands/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -464,7 +464,11 @@ fn render_top_capacity<B: Backend>(index: &IndexController, ctx: RenderContext<B
.map(|s| s.as_str())
.unwrap_or("null")
)),
Text::raw(format!(" [capacity]: {}", result.capacity)),
Text::raw(format!(
" [capacity]: {} ({})",
result.capacity,
human_capacity(result.capacity)
)),
]
});
List::new(lines).render(ctx.frame, top_capacity_chunks[0]);
Expand Down
11 changes: 11 additions & 0 deletions src/subcommands/tui/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ pub fn ts_now() -> 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,
Expand Down

0 comments on commit d1d2fae

Please sign in to comment.