Skip to content

Commit

Permalink
tui/pretty: Ensure we never hit 0 for column width limits
Browse files Browse the repository at this point in the history
This fixes issue #315 by enforcing our longest width is at least 1 with
a saturating sub. Additionally we fix the column padding to match the old
D implementation.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Aug 17, 2024
1 parent 4966f0f commit 4e5b424
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/tui/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn column_printer<T: ColumnDisplay>(items: &[T], colnum: Option<usize>) {
let Some(largest_element) = items.iter().max_by_key(|p| p.get_display_width()) else {
return;
};
let largest_width = min(max_width, largest_element.get_display_width());
let largest_width = min(max_width, largest_element.get_display_width() + 1);

let colnum = colnum.unwrap_or_else(|| max(1, max_width / largest_width));
let rownum = ((items.len() as f32) / (colnum as f32)).ceil() as usize;
Expand Down
4 changes: 2 additions & 2 deletions moss/src/package/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use tui::{

use crate::Package;

/// We always pad columns by 4 spaces to just not jank up the output
const COLUMN_PADDING: usize = 4;
/// We always pad columns by 3 spaces to just not jank up the output
const COLUMN_PADDING: usize = 3;

/// Allow display packages in column form
impl ColumnDisplay for Package {
Expand Down

0 comments on commit 4e5b424

Please sign in to comment.