diff --git a/src/lib.rs b/src/lib.rs index 3763d73..6944338 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,7 +113,7 @@ impl Default for AsciiTable { pub struct Column { pub header: String, pub align: Align, - pub max_width: usize // TODO: + pub max_width: usize } impl Column { @@ -194,13 +194,17 @@ impl AsciiTable { false } else if num_cols == 0 { false - } else if self.max_width < ((num_cols - 1) * 3) + 4 { + } else if self.max_width < Self::smallest_width(num_cols) { false } else { true } } + fn smallest_width(num_cols: usize) -> usize { + ((num_cols - 1) * 3) + 4 + } + fn stringify(&self, data: L1) -> Vec> where L1: IntoIterator, L2: IntoIterator, @@ -230,7 +234,7 @@ impl AsciiTable { fn truncate_widths(&self, mut widths: Vec) -> Vec { let max_width = self.max_width; - let table_padding = ((widths.len() - 1) * 3) + 4; + let table_padding = Self::smallest_width(widths.len()); while widths.iter().sum::() + table_padding > max_width && *widths.iter().max().unwrap() > 0 { let max = widths.iter().max().unwrap();