1 | //! This module contains primitives to create a spread row. |
2 | //! Ultimately it is a cell with a span set to a number of columns on the [`Table`]. |
3 | //! |
4 | //! You can use a [`Span`] to set a custom span. |
5 | //! |
6 | //! # Example |
7 | //! |
8 | //! ``` |
9 | //! use tabled::{Table, settings::Panel}; |
10 | //! |
11 | //! let data = [[1, 2, 3], [4, 5, 6]]; |
12 | //! |
13 | //! let table = Table::new(data) |
14 | //! .with(Panel::vertical(1, "S \np \nl \ni \nt" )) |
15 | //! .with(Panel::header("Numbers" )) |
16 | //! .to_string(); |
17 | //! |
18 | //! println!("{}" , table); |
19 | //! |
20 | //! assert_eq!( |
21 | //! table, |
22 | //! concat!( |
23 | //! "+---+---+---+---+ \n" , |
24 | //! "| Numbers | \n" , |
25 | //! "+---+---+---+---+ \n" , |
26 | //! "| 0 | S | 1 | 2 | \n" , |
27 | //! "+---+ p +---+---+ \n" , |
28 | //! "| 1 | l | 2 | 3 | \n" , |
29 | //! "+---+ i +---+---+ \n" , |
30 | //! "| 4 | t | 5 | 6 | \n" , |
31 | //! "+---+---+---+---+" , |
32 | //! ) |
33 | //! ) |
34 | //! ``` |
35 | //! |
36 | //! [`Table`]: crate::Table |
37 | //! [`Span`]: crate::settings::span::Span |
38 | |
39 | mod footer; |
40 | mod header; |
41 | mod horizontal_panel; |
42 | mod vertical_panel; |
43 | |
44 | pub use footer::Footer; |
45 | pub use header::Header; |
46 | pub use horizontal_panel::HorizontalPanel; |
47 | pub use vertical_panel::VerticalPanel; |
48 | |
49 | /// Panel allows to add a Row which has 1 continues Cell to a [`Table`]. |
50 | /// |
51 | /// See `examples/panel.rs`. |
52 | /// |
53 | /// [`Table`]: crate::Table |
54 | #[derive (Debug)] |
55 | pub struct Panel; |
56 | |
57 | impl Panel { |
58 | /// Creates an empty vertical row at given index. |
59 | /// |
60 | /// ``` |
61 | /// use tabled::{settings::Panel, Table}; |
62 | /// |
63 | /// let data = [[1, 2, 3], [4, 5, 6]]; |
64 | /// |
65 | /// let table = Table::new(data) |
66 | /// .with(Panel::vertical(1, "Tabled Releases" )) |
67 | /// .to_string(); |
68 | /// |
69 | /// println!("{}" , table); |
70 | /// |
71 | /// assert_eq!( |
72 | /// table, |
73 | /// concat!( |
74 | /// "+---+-----------------+---+---+ \n" , |
75 | /// "| 0 | Tabled Releases | 1 | 2 | \n" , |
76 | /// "+---+ +---+---+ \n" , |
77 | /// "| 1 | | 2 | 3 | \n" , |
78 | /// "+---+ +---+---+ \n" , |
79 | /// "| 4 | | 5 | 6 | \n" , |
80 | /// "+---+-----------------+---+---+" , |
81 | /// ) |
82 | /// ) |
83 | /// ``` |
84 | pub fn vertical<S: AsRef<str>>(column: usize, text: S) -> VerticalPanel<S> { |
85 | VerticalPanel::new(column, text) |
86 | } |
87 | |
88 | /// Creates an empty horizontal row at given index. |
89 | /// |
90 | /// ``` |
91 | /// use tabled::{Table, settings::Panel}; |
92 | /// |
93 | /// let data = [[1, 2, 3], [4, 5, 6]]; |
94 | /// |
95 | /// let table = Table::new(data) |
96 | /// .with(Panel::vertical(1, "" )) |
97 | /// .to_string(); |
98 | /// |
99 | /// println!("{}" , table); |
100 | /// |
101 | /// assert_eq!( |
102 | /// table, |
103 | /// concat!( |
104 | /// "+---+--+---+---+ \n" , |
105 | /// "| 0 | | 1 | 2 | \n" , |
106 | /// "+---+ +---+---+ \n" , |
107 | /// "| 1 | | 2 | 3 | \n" , |
108 | /// "+---+ +---+---+ \n" , |
109 | /// "| 4 | | 5 | 6 | \n" , |
110 | /// "+---+--+---+---+" , |
111 | /// ) |
112 | /// ) |
113 | /// ``` |
114 | pub fn horizontal<S: AsRef<str>>(row: usize, text: S) -> HorizontalPanel<S> { |
115 | HorizontalPanel::new(row, text) |
116 | } |
117 | |
118 | /// Creates an horizontal row at first row. |
119 | pub fn header<S: AsRef<str>>(text: S) -> Header<S> { |
120 | Header::new(text) |
121 | } |
122 | |
123 | /// Creates an horizontal row at last row. |
124 | pub fn footer<S: AsRef<str>>(text: S) -> Footer<S> { |
125 | Footer::new(text) |
126 | } |
127 | } |
128 | |