Debian Codegraph @

src/style/table.rs

raw symbols SCIP
1 /// Specify how comfy_table should arrange the content in your table.
2 ///
3 /// ```
4 /// use comfy_table::{ContentArrangement, Table};
5 ///
6 /// let mut table = Table::new();
7 /// table.set_content_arrangement(ContentArrangement::Dynamic);
8 /// ```
9 #[derive(Clone, Debug)]
10 pub 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
23 /// fallback.
24 Dynamic,
25 /// This is mode is the same as the [ContentArrangement::Dynamic] arrangement, but it will
26 /// always use as much space as it's given. Any surplus space will be distributed between
27 /// all columns.
28 DynamicFullWidth,
29 }
30
31 /// All configurable table components.
32 /// A character can be assigned to each component via
33 /// [Table::set_style](crate::table::Table::set_style). This is then used to draw character of the
34 /// respective component to the commandline.
35 ///
36 /// I hope that most component names are self-explanatory. Just in case:
37 /// BorderIntersections are Intersections, where rows/columns lines meet outer borders.
38 /// E.g.:
39 /// ```text
40 /// ---------
41 /// v |
42 /// +---+---+---+ |
43 /// | a | b | c | |
44 /// +===+===+===+<-|
45 /// | | | | |
46 /// +---+---+---+<-- These "+" chars are Borderintersections.
47 /// | | | | The inner "+" chars are MiddleIntersections
48 /// +---+---+---+
49 /// ```
50 #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
51 pub enum TableComponent {
52 LeftBorder,
53 RightBorder,
54 TopBorder,
55 BottomBorder,
56 LeftHeaderIntersection,
57 HeaderLines,
58 MiddleHeaderIntersections,
59 RightHeaderIntersection,
60 VerticalLines,
61 HorizontalLines,
62 MiddleIntersections,
63 LeftBorderIntersections,
64 RightBorderIntersections,
65 TopBorderIntersections,
66 BottomBorderIntersections,
67 TopLeftCorner,
68 TopRightCorner,
69 BottomLeftCorner,
70 BottomRightCorner,
71 }
72
73 impl TableComponent {
74 const fn components() -> [TableComponent; 19] {
75 [
76 TableComponent::LeftBorder,
77 TableComponent::RightBorder,
78 TableComponent::TopBorder,
79 TableComponent::BottomBorder,
80 TableComponent::LeftHeaderIntersection,
81 TableComponent::HeaderLines,
82 TableComponent::MiddleHeaderIntersections,
83 TableComponent::RightHeaderIntersection,
84 TableComponent::VerticalLines,
85 TableComponent::HorizontalLines,
86 TableComponent::MiddleIntersections,
87 TableComponent::LeftBorderIntersections,
88 TableComponent::RightBorderIntersections,
89 TableComponent::TopBorderIntersections,
90 TableComponent::BottomBorderIntersections,
91 TableComponent::TopLeftCorner,
92 TableComponent::TopRightCorner,
93 TableComponent::BottomLeftCorner,
94 TableComponent::BottomRightCorner,
95 ]
96 }
97
98 pub fn iter() -> impl Iterator<Item = TableComponent> {
99 TableComponent::components().into_iter()
100 }
101 }