//! Print column-aligned text to the console. //! //! Example: //! ``` //! use radicle_term::table::*; //! //! let mut t = Table::new(TableOptions::default()); //! t.push(["pest", "biological control"]); //! t.push(["aphid", "lacewing"]); //! t.push(["spider mite", "ladybug"]); //! t.print(); //! ``` //! Output: //! ``` plain //! pest biological control //! aphid ladybug //! spider mite persimilis //! ``` use std::fmt; use crate as term; use crate::cell::Cell; use crate::{Color, Label, Line, Max, Paint, Size}; pub use crate::Element; #[derive(Debug)] pub struct TableOptions { /// Whether the table should be allowed to overflow. pub overflow: bool, /// The maximum width and height. pub max: Max, /// Horizontal spacing between table cells. pub spacing: usize, /// Table border. pub border: Option, } impl Default for TableOptions { fn default() -> Self { Self { overflow: false, max: Max::default(), spacing: 1, border: None, } } } impl TableOptions { pub fn bordered() -> Self { Self { border: Some(term::colors::FAINT), spacing: 3, ..Self::default() } } } #[derive(Debug)] enum Row { Data([T; W]), Divider, } #[derive(Debug)] pub struct Table { rows: Vec>, widths: [usize; W], opts: TableOptions, } impl Default for Table { fn default() -> Self { Self { rows: Vec::new(), widths: [0; W], opts: TableOptions::default(), } } } impl Element for Table where T::Padded: Into