1 | use crate::{ |
2 | grid::config::SpannedConfig, |
3 | grid::dimension::SpannedGridDimension, |
4 | grid::records::{IntoRecords, Records}, |
5 | }; |
6 | |
7 | pub(crate) fn get_table_widths<R>(records: R, cfg: &SpannedConfig) -> Vec<usize> |
8 | where |
9 | R: Records, |
10 | <R::Iter as IntoRecords>::Cell: AsRef<str>, |
11 | { |
12 | SpannedGridDimension::width(records, cfg) |
13 | } |
14 | |
15 | pub(crate) fn get_table_widths_with_total<R>(records: R, cfg: &SpannedConfig) -> (Vec<usize>, usize) |
16 | where |
17 | R: Records, |
18 | <R::Iter as IntoRecords>::Cell: AsRef<str>, |
19 | { |
20 | let widths: Vec = SpannedGridDimension::width(records, cfg); |
21 | let total_width: usize = get_table_total_width(&widths, cfg); |
22 | (widths, total_width) |
23 | } |
24 | |
25 | fn get_table_total_width(list: &[usize], cfg: &SpannedConfig) -> usize { |
26 | let margin: Sides = cfg.get_margin(); |
27 | list.iter().sum::<usize>() |
28 | + cfg.count_vertical(count_columns:list.len()) |
29 | + margin.left.size |
30 | + margin.right.size |
31 | } |
32 | |