Skip to content

Commit

Permalink
bug: fix incorrect basic cpu spacing (#291)
Browse files Browse the repository at this point in the history
Fixes a bug with CPU spacing on basic mode.
  • Loading branch information
ClementTsang authored Nov 3, 2020
1 parent 9e85871 commit e8358f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
8 changes: 5 additions & 3 deletions src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit e8358f8

Please sign in to comment.