comfy_table/style/table.rs
1/// Specify how comfy_table should arrange the content in your table.
2///
3/// ```
4/// use comfy_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 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 TopLeftCorner,
65 TopRightCorner,
66 BottomLeftCorner,
67 BottomRightCorner,
68}
69
70impl TableComponent {
71 const fn components() -> [TableComponent; 19] {
72 [
73 TableComponent::LeftBorder,
74 TableComponent::RightBorder,
75 TableComponent::TopBorder,
76 TableComponent::BottomBorder,
77 TableComponent::LeftHeaderIntersection,
78 TableComponent::HeaderLines,
79 TableComponent::MiddleHeaderIntersections,
80 TableComponent::RightHeaderIntersection,
81 TableComponent::VerticalLines,
82 TableComponent::HorizontalLines,
83 TableComponent::MiddleIntersections,
84 TableComponent::LeftBorderIntersections,
85 TableComponent::RightBorderIntersections,
86 TableComponent::TopBorderIntersections,
87 TableComponent::BottomBorderIntersections,
88 TableComponent::TopLeftCorner,
89 TableComponent::TopRightCorner,
90 TableComponent::BottomLeftCorner,
91 TableComponent::BottomRightCorner,
92 ]
93 }
94
95 pub fn iter() -> impl Iterator<Item = TableComponent> {
96 TableComponent::components().into_iter()
97 }
98}