refactor: Add CPU load back

This commit is contained in:
ClementTsang 2021-11-23 22:34:50 -05:00
parent 16babea202
commit e89d46e10f
2 changed files with 14 additions and 5 deletions

View File

@ -12,6 +12,7 @@ use crate::{
event::{ComponentEventResult, SelectionAction},
text_table::SimpleColumn,
time_graph::TimeGraphData,
widgets::tui_stuff::BlockBuilder,
AppConfigFields, Component, DataCollection, TextTable, TimeGraph, Widget,
},
canvas::Painter,
@ -251,8 +252,14 @@ impl Widget for CpuGraph {
})
.collect::<Vec<_>>();
let graph_block = self
.block()
let name = format!(
"{} ─ {:.2} {:.2} {:.2}",
self.get_pretty_name(),
self.load_avg_data[0],
self.load_avg_data[1],
self.load_avg_data[2],
);
let graph_block = BlockBuilder::new(name)
.selected(selected && matches!(&self.selected, CpuGraphSelection::Graph))
.show_esc(expanded)
.build(painter, graph_block_area);

View File

@ -1,3 +1,5 @@
use std::borrow::Cow;
use tui::{
layout::Rect,
text::Span,
@ -11,19 +13,19 @@ pub struct BlockBuilder {
borders: Borders,
selected: bool,
show_esc: bool,
name: &'static str,
name: Cow<'static, str>,
hide_title: bool,
extra_text: Option<String>,
}
impl BlockBuilder {
/// Creates a new [`BlockBuilder`] with the name of block.
pub fn new(name: &'static str) -> Self {
pub fn new<S: Into<Cow<'static, str>>>(name: S) -> Self {
Self {
borders: Borders::ALL,
selected: false,
show_esc: false,
name,
name: name.into(),
hide_title: false,
extra_text: None,
}