diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-09-26 20:04:34 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-09-26 20:21:59 -0400 |
commit | 750d8f3cb747103cca7a2a4afe8ff41ff1318b6f (patch) | |
tree | ac34a6a538c1f94cb395b20a23c9186b749ca6e6 /src/canvas/widgets/cpu_basic.rs | |
parent | 6db76029e2419d53c81cb2111e487f83ee248a2f (diff) |
refactor: tui-rs 0.11.0 refactor (#253)
Refactors tui-rs usage to the new 0.11.0 release. This release also fixes the highlighting bug from #249, and now, expanding a widget no longer overrides the widget title colour.
This commit also introduces #255, but that seems to be easy to bandaid so hopefully it will get fixed soon?
Diffstat (limited to 'src/canvas/widgets/cpu_basic.rs')
-rw-r--r-- | src/canvas/widgets/cpu_basic.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index 7f9381f9..2f7574b6 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -11,7 +11,8 @@ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Paragraph, Text}, + text::{Span, Spans}, + widgets::{Block, Paragraph}, }; pub trait CpuBasicWidget { @@ -76,7 +77,7 @@ impl CpuBasicWidget for Painter { let num_bars = calculate_basic_use_bars(use_percentage, bar_length); format!( - "{:3}[{}{}{:3.0}%]\n", + "{:3}[{}{}{:3.0}%]", if app_state.app_config_fields.show_average_cpu { if cpu_index == 0 { "AVG".to_string() @@ -108,16 +109,11 @@ impl CpuBasicWidget for Painter { let end_index = min(start_index + how_many_cpus, num_cpus); let cpu_column = (start_index..end_index) .map(|cpu_index| { - // Spans::from(Span { - // content: (&cpu_bars[cpu_index]).into(), - // style: self.colours.cpu_colour_styles - // [cpu_index % self.colours.cpu_colour_styles.len()], - // }) - Text::styled( - &cpu_bars[cpu_index], - self.colours.cpu_colour_styles + Spans::from(Span { + content: (&cpu_bars[cpu_index]).into(), + style: self.colours.cpu_colour_styles [cpu_index % self.colours.cpu_colour_styles.len()], - ) + }) }) .collect::<Vec<_>>(); @@ -130,7 +126,7 @@ impl CpuBasicWidget for Painter { .split(*chunk)[0]; f.render_widget( - Paragraph::new(cpu_column.iter()).block(Block::default()), + Paragraph::new(cpu_column).block(Block::default()), margined_loc, ); } |