pub mod arrangement;
pub mod formatting;
use crate::style::{CellAlignment, ColumnConstraint};
use crate::{Column, Table};
use arrangement::arrange_content;
use formatting::borders::draw_borders;
use formatting::content_format::format_content;
#[derive(Debug)]
pub struct ColumnDisplayInfo {
pub padding: (u16, u16),
pub delimiter: Option<char>,
pub content_width: u16,
pub cell_alignment: Option<CellAlignment>,
is_hidden: bool,
}
impl ColumnDisplayInfo {
pub fn new(column: &Column, mut content_width: u16) -> Self {
if content_width == 0 {
content_width = 1;
}
Self {
padding: column.padding,
delimiter: column.delimiter,
content_width,
cell_alignment: column.cell_alignment,
is_hidden: matches!(column.constraint, Some(ColumnConstraint::Hidden)),
}
}
pub fn width(&self) -> u16 {
self.content_width + self.padding.0 + self.padding.1
}
}
pub fn build_table(table: &Table) -> impl Iterator<Item = String> {
let display_info = arrange_content(table);
let content = format_content(table, &display_info);
draw_borders(table, &content, &display_info).into_iter()
}