Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Workaround for strange rendering when there are <4 CPU entries reported #398

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/data_harvester/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
16 changes: 7 additions & 9 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
},
})
})
Expand Down