Refactoring.

This commit is contained in:
Gerrit Viljoen 2020-04-02 09:33:01 +02:00
parent f501c4ac0c
commit 71f651f36a

View File

@ -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<L1, L2, T>(&self, data: L1) -> Vec<Vec<String>>
where L1: IntoIterator<Item = L2>,
L2: IntoIterator<Item = T>,
@ -230,7 +234,7 @@ impl AsciiTable {
fn truncate_widths(&self, mut widths: Vec<usize>) -> Vec<usize> {
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::<usize>() + table_padding > max_width &&
*widths.iter().max().unwrap() > 0 {
let max = widths.iter().max().unwrap();