mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
Refactoring.
This commit is contained in:
parent
0adc7b97bd
commit
096fd2cfa4
12
src/lib.rs
12
src/lib.rs
@ -129,13 +129,11 @@ fn correct_config(conf: &TableConfig, num_cols: usize) -> TableConfig {
|
||||
}
|
||||
|
||||
fn column_widths(data: &Vec<Vec<String>>, conf: &TableConfig) -> Vec<u32> {
|
||||
let header_widths = conf.columns.iter().map(|(_, x)| x.header.chars().count());
|
||||
let data_widths = (0..conf.columns.len()).map(|a|
|
||||
data.iter().map(|row|
|
||||
if a < row.len() {row[a].chars().count()} else {0}
|
||||
).max().unwrap_or(0)
|
||||
);
|
||||
let result = header_widths.zip(data_widths).map(|(x, y)| x.max(y) as u32).collect();
|
||||
let result: Vec<_> = (0..conf.columns.len()).map(|a| {
|
||||
let column_width = data.iter().map(|row| row[a].chars().count()).max().unwrap();
|
||||
let header_width = conf.columns[&a].header.chars().count();
|
||||
column_width.max(header_width) as u32
|
||||
}).collect();
|
||||
trunc(result, conf)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user