super_table/style/
table.rs

1/// Specify how super_table should arrange the content in your table.
2///
3/// ```
4/// use super_table::{Table, ContentArrangement};
5///
6/// let mut table = Table::new();
7/// table.set_content_arrangement(ContentArrangement::Dynamic);
8/// ```
9#[derive(Clone, Debug)]
10pub enum ContentArrangement {
11    /// Don't do any content arrangement.\
12    /// Tables with this mode might become wider than your output and look ugly.\
13    /// Constraints on columns are still respected.
14    Disabled,
15    /// Dynamically determine the width of columns in regard to terminal width and content length.\
16    /// With this mode, the content in cells will wrap dynamically to get the best column layout
17    /// for the given content.\
18    /// Constraints on columns are still respected.
19    ///
20    /// **Warning:** If terminal width cannot be determined and no table_width is set via
21    /// [Table::set_width](crate::table::Table::set_width),
22    /// this option won't work and [Disabled](ContentArrangement::Disabled) will be used as a fallback.
23    Dynamic,
24    /// This is mode is the same as the [ContentArrangement::Dynamic] arrangement, but it will always use as much
25    /// space as it's given. Any surplus space will be distributed between all columns.
26    DynamicFullWidth,
27}
28
29/// All configurable table components.
30/// A character can be assigned to each component via [Table::set_style](crate::table::Table::set_style).
31/// This is then used to draw character of the respective component to the commandline.
32///
33/// I hope that most component names are self-explanatory. Just in case:
34/// BorderIntersections are Intersections, where rows/columns lines meet outer borders.
35/// E.g.:
36/// ```text
37///        ---------
38///        v       |
39/// +---+---+---+  |
40/// | a | b | c |  |
41/// +===+===+===+<-|
42/// |   |   |   |  |
43/// +---+---+---+<-- These "+" chars are Borderintersections.
44/// |   |   |   |    The inner "+" chars are MiddleIntersections
45/// +---+---+---+
46/// ```
47#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
48pub enum TableComponent {
49    LeftBorder,
50    RightBorder,
51    TopBorder,
52    BottomBorder,
53    LeftHeaderIntersection,
54    HeaderLines,
55    MiddleHeaderIntersections,
56    RightHeaderIntersection,
57    VerticalLines,
58    HorizontalLines,
59    MiddleIntersections,
60    LeftBorderIntersections,
61    RightBorderIntersections,
62    TopBorderIntersections,
63    BottomBorderIntersections,
64    /// Used at the bottom border where a colspan cell merges columns above.
65    /// Typically renders as '─' to create a continuous line instead of '┴'.
66    BottomBorderColspanIntersections,
67    /// Used at the header separator where a colspan or rowspan starts in the row below.
68    /// This character should have a top connector (to vertical line in header) and
69    /// horizontal continuation, but no bottom connector since the column boundary
70    /// does not continue into the data rows.
71    /// Typically renders as '╧' for UTF-8 (up single and horizontal double) or '=' for ASCII.
72    MiddleHeaderMergeIntersection,
73    TopLeftCorner,
74    TopRightCorner,
75    BottomLeftCorner,
76    BottomRightCorner,
77}
78
79impl TableComponent {
80    const fn components() -> [TableComponent; 21] {
81        [
82            TableComponent::LeftBorder,
83            TableComponent::RightBorder,
84            TableComponent::TopBorder,
85            TableComponent::BottomBorder,
86            TableComponent::LeftHeaderIntersection,
87            TableComponent::HeaderLines,
88            TableComponent::MiddleHeaderIntersections,
89            TableComponent::RightHeaderIntersection,
90            TableComponent::VerticalLines,
91            TableComponent::HorizontalLines,
92            TableComponent::MiddleIntersections,
93            TableComponent::LeftBorderIntersections,
94            TableComponent::RightBorderIntersections,
95            TableComponent::TopBorderIntersections,
96            TableComponent::BottomBorderIntersections,
97            TableComponent::BottomBorderColspanIntersections,
98            TableComponent::MiddleHeaderMergeIntersection,
99            TableComponent::TopLeftCorner,
100            TableComponent::TopRightCorner,
101            TableComponent::BottomLeftCorner,
102            TableComponent::BottomRightCorner,
103        ]
104    }
105
106    pub fn iter() -> impl Iterator<Item = TableComponent> {
107        TableComponent::components().into_iter()
108    }
109}