diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-01-25 02:21:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-25 02:21:33 -0500 |
commit | d48e6cd7e080432daeca54a0aff9271c60a45107 (patch) | |
tree | f37c9eb8f9b917b491a00b627ee807efe54d429e | |
parent | 9822478454c419ccc1d02ed11c9a2cafbfe78a02 (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.
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | src/app/data_harvester/cpu.rs | 1 | ||||
-rw-r--r-- | src/canvas.rs | 16 | ||||
-rw-r--r-- | src/canvas/widgets/cpu_basic.rs | 2 |
4 files changed, 17 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f56404fa..0244604e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#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. @@ -27,6 +33,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/app/data_harvester/cpu.rs b/src/app/data_harvester/cpu.rs index c154cfa1..4bc4cb94 100644 --- a/src/app/data_harvester/cpu.rs +++ b/src/app/data_harvester/cpu.rs @@ -189,5 +189,6 @@ pub async fn get_cpu_data_list( }) } + // Ok(Vec::from(cpu_deque.drain(0..5).collect::<Vec<_>>())) Ok(Vec::from(cpu_deque)) } diff --git a/src/canvas.rs b/src/canvas.rs index e0aff886..d583a01b 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -520,18 +520,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()] }, }) }) |