1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::DisplayInfos;
use crate::utils::formatting::borders::{
should_draw_left_border, should_draw_right_border, should_draw_vertical_lines,
};
use crate::{Cell, Column, Table};
pub fn absolute_width_with_padding(column: &Column, width: u16) -> u16 {
let (left, right) = column.padding;
let mut content_width = i32::from(width) - i32::from(left) - i32::from(right);
if content_width <= 0 {
content_width = 1;
}
content_width.try_into().unwrap_or(u16::MAX)
}
pub fn count_visible_columns(columns: &[Column]) -> usize {
columns.iter().filter(|column| !column.is_hidden()).count()
}
pub fn count_remaining_columns(column_count: usize, infos: &DisplayInfos) -> usize {
column_count - infos.iter().filter(|(_, info)| !info.is_hidden).count()
}
pub fn count_border_columns(table: &Table, visible_columns: usize) -> usize {
let mut lines = 0;
if should_draw_left_border(table) {
lines += 1;
}
if should_draw_right_border(table) {
lines += 1;
}
if should_draw_vertical_lines(table) {
lines += visible_columns.saturating_sub(1);
}
lines
}
pub fn delimiter(table: &Table, column: &Column, cell: &Cell) -> char {
if let Some(delimiter) = cell.delimiter {
delimiter
} else if let Some(delimiter) = column.delimiter {
delimiter
} else if let Some(delimiter) = table.delimiter {
delimiter
} else {
' '
}
}