summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-11-02 22:39:02 -0500
committerGitHub <noreply@github.com>2020-11-02 22:39:02 -0500
commite8358f8f47f707b2af99e3b69dd1d7c3d2ca0ef3 (patch)
tree6e783692e52373ecf81d32a557ee596a25171801
parent9e858713fda0c622e74b47bca14bf985655273da (diff)
bug: fix incorrect basic cpu spacing (#291)
Fixes a bug with CPU spacing on basic mode.
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/app.rs2
-rw-r--r--src/canvas/widgets/cpu_basic.rs8
3 files changed, 8 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 558e7285..6976b15f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#290](https://github.com/ClementTsang/bottom/pull/290): Fixed an incorrect offset affecting the CPU colour when scrolling.
+- [#291](https://github.com/ClementTsang/bottom/pull/291): Fixed spacing problems in basic CPU mode.
+
## [0.4.7] - 2020-08-26
### Bug Fixes
diff --git a/src/app.rs b/src/app.rs
index 2f63853f..d80a206c 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1404,7 +1404,7 @@ impl App {
/// Call this whenever the config value is updated!
fn update_config_file(&mut self) -> anyhow::Result<()> {
if self.app_config_fields.no_write {
- debug!("No write enabled. Config will not be written.");
+ // debug!("No write enabled. Config will not be written.");
// Don't write!
// FIXME: [CONFIG] This should be made VERY clear to the user... make a thing saying "it will not write due to no_write option"
Ok(())
diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs
index c42350cc..8e6b332f 100644
--- a/src/canvas/widgets/cpu_basic.rs
+++ b/src/canvas/widgets/cpu_basic.rs
@@ -26,7 +26,7 @@ impl CpuBasicWidget for Painter {
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
// Skip the first element, it's the "all" element
- if !app_state.canvas_data.cpu_data.is_empty() {
+ if app_state.canvas_data.cpu_data.len() > 1 {
let cpu_data: &[ConvertedCpuData] = &app_state.canvas_data.cpu_data[1..];
// This is a bit complicated, but basically, we want to draw SOME number
@@ -64,7 +64,7 @@ impl CpuBasicWidget for Painter {
// +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
const MARGIN_SPACE: usize = 2;
let remaining_width = usize::from(draw_loc.width)
- .saturating_sub((9 + MARGIN_SPACE) * REQUIRED_COLUMNS - MARGIN_SPACE);
+ .saturating_sub((9 + MARGIN_SPACE) * REQUIRED_COLUMNS);
let bar_length = remaining_width / REQUIRED_COLUMNS;
@@ -100,7 +100,8 @@ impl CpuBasicWidget for Painter {
let mut row_counter = num_cpus;
let mut start_index = 0;
for (itx, chunk) in chunks.iter().enumerate() {
- // Explicitly check... don't want an accidental DBZ or underflow
+ // Explicitly check... don't want an accidental DBZ or underflow, this ensures
+ // to_divide is > 0
if REQUIRED_COLUMNS > itx {
let to_divide = REQUIRED_COLUMNS - itx;
let how_many_cpus = min(
@@ -110,6 +111,7 @@ impl CpuBasicWidget for Painter {
);
row_counter -= how_many_cpus;
let end_index = min(start_index + how_many_cpus, num_cpus);
+
let cpu_column = (start_index..end_index)
.map(|cpu_index| {
Spans::from(Span {