bug: fix incorrect basic cpu spacing (#291)

Fixes a bug with CPU spacing on basic mode.
This commit is contained in:
Clement Tsang 2020-11-02 22:39:02 -05:00 committed by GitHub
parent 9e858713fd
commit e8358f8f47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -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. - [#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 ## [0.4.7] - 2020-08-26
### Bug Fixes ### Bug Fixes

View file

@ -1404,7 +1404,7 @@ impl App {
/// Call this whenever the config value is updated! /// Call this whenever the config value is updated!
fn update_config_file(&mut self) -> anyhow::Result<()> { fn update_config_file(&mut self) -> anyhow::Result<()> {
if self.app_config_fields.no_write { 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! // 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" // 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(()) Ok(())

View file

@ -26,7 +26,7 @@ impl CpuBasicWidget for Painter {
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) { ) {
// Skip the first element, it's the "all" element // 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..]; let cpu_data: &[ConvertedCpuData] = &app_state.canvas_data.cpu_data[1..];
// This is a bit complicated, but basically, we want to draw SOME number // 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 // +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
const MARGIN_SPACE: usize = 2; const MARGIN_SPACE: usize = 2;
let remaining_width = usize::from(draw_loc.width) 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; let bar_length = remaining_width / REQUIRED_COLUMNS;
@ -100,7 +100,8 @@ impl CpuBasicWidget for Painter {
let mut row_counter = num_cpus; let mut row_counter = num_cpus;
let mut start_index = 0; let mut start_index = 0;
for (itx, chunk) in chunks.iter().enumerate() { 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 { if REQUIRED_COLUMNS > itx {
let to_divide = REQUIRED_COLUMNS - itx; let to_divide = REQUIRED_COLUMNS - itx;
let how_many_cpus = min( let how_many_cpus = min(
@ -110,6 +111,7 @@ impl CpuBasicWidget for Painter {
); );
row_counter -= how_many_cpus; row_counter -= how_many_cpus;
let end_index = min(start_index + how_many_cpus, num_cpus); let end_index = min(start_index + how_many_cpus, num_cpus);
let cpu_column = (start_index..end_index) let cpu_column = (start_index..end_index)
.map(|cpu_index| { .map(|cpu_index| {
Spans::from(Span { Spans::from(Span {