summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-01-25 02:21:33 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2021-01-25 02:23:52 -0500
commita3ed45ae96d46fe739a0321f62734083affcf0b9 (patch)
tree43e2c08f17c8e882bccfd39cc2f1a3604cd8ff6f
parent6d0e8e14593e47db14e392465d47f14b4176c950 (diff)
bug: Workaround for strange rendering when there are <4 CPU entries reported (#398)
So it seems that tui-rs doesn't like rendering my CPU bars if the height is exactly 1. It needs at least 2. I have no idea why, this is probably something weird with how I render. This, of course, breaks when there is only one row to report (i.e. with a dual core setup in #397). The workaround switches the gap between the CPU and mem/net parts to 0, and increases the CPU's draw height by 1, only when the height is otherwise 1 (so the draw height is now at least 2). This does have the side effect of including an extra line to the side borders, but I think it's fine. (cherry picked from commit d48e6cd7e080432daeca54a0aff9271c60a45107)
-rw-r--r--CHANGELOG.md10
-rw-r--r--src/canvas.rs16
-rw-r--r--src/canvas/widgets/cpu_basic.rs2
3 files changed, 18 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82ecc3ab..e12ca623 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Changes
+- [#372](https://github.com/ClementTsang/bottom/pull/372): Hides the SWAP graph and legend in normal mode if SWAP is 0.
+
+- [#390](https://github.com/ClementTsang/bottom/pull/390): macOS shouldn't need elevated privileges to see CPU usage on all processes now.
+
+- [#391](https://github.com/ClementTsang/bottom/pull/391): Show degree symbol on Celsius and Fahrenheit.
+
+## [0.5.7] - Unreleased
+
## Bug Fixes
- [#373](https://github.com/ClementTsang/bottom/pull/373): Fixes incorrect colours being used the CPU widget in basic mode.
@@ -21,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#389](https://github.com/ClementTsang/bottom/pull/389): Fixes the sorting arrow disappearing in proc widget under some cases.
+- [#398](https://github.com/ClementTsang/bottom/pull/398): Fixes basic mode failing to report CPUs if there are less than 4 entries to report.
+
## [0.5.6] - 2020-12-17
## Bug Fixes
diff --git a/src/canvas.rs b/src/canvas.rs
index 7c63b0ba..f49f27af 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -517,18 +517,16 @@ impl Painter {
self.draw_frozen_indicator(&mut f, frozen_draw_loc);
}
+ let actual_cpu_data_len = app_state.canvas_data.cpu_data.len().saturating_sub(1);
+ let cpu_height = (actual_cpu_data_len / 4) as u16
+ + (if actual_cpu_data_len % 4 == 0 { 0 } else { 1 });
+
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
+ .margin(0)
.constraints([
- Constraint::Length(
- (app_state.canvas_data.cpu_data.len() / 4) as u16
- + (if app_state.canvas_data.cpu_data.len() % 4 == 0 {
- 0
- } else {
- 1
- }),
- ),
- Constraint::Length(1),
+ Constraint::Length(cpu_height + if cpu_height <= 1 { 1 } else { 0 }), // This fixes #397, apparently if the height is 1, it can't render the CPU bars...
+ Constraint::Length(if cpu_height <= 1 { 0 } else { 1 }),
Constraint::Length(2),
Constraint::Length(2),
Constraint::Min(5),
diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs
index 1ac1b3a6..5beb3f73 100644
--- a/src/canvas/widgets/cpu_basic.rs
+++ b/src/canvas/widgets/cpu_basic.rs
@@ -171,7 +171,7 @@ impl CpuBasicWidget for Painter {
}
} else {
self.colours.cpu_colour_styles
- [(itx - 1) % self.colours.cpu_colour_styles.len()]
+ [itx % self.colours.cpu_colour_styles.len()]
},
})
})