1 | //! This module contains a list of primitives which can be applied to change [`Table`] style. |
2 | //! |
3 | //! ## [`Style`] |
4 | //! |
5 | //! It is responsible for a table border style. |
6 | //! An individual cell border can be set by [`Border`]. |
7 | //! |
8 | //! ### Example |
9 | //! |
10 | #![cfg_attr (feature = "std" , doc = "```" )] |
11 | #![cfg_attr (not(feature = "std" ), doc = "```ignore" )] |
12 | //! use tabled::{Table, settings::Style}; |
13 | //! |
14 | //! let data = vec!["Hello" , "2022" ]; |
15 | //! let mut table = Table::new(&data); |
16 | //! table.with(Style::psql()); |
17 | //! |
18 | //! assert_eq!( |
19 | //! table.to_string(), |
20 | //! concat!( |
21 | //! " &str \n" , |
22 | //! "------- \n" , |
23 | //! " Hello \n" , |
24 | //! " 2022 " , |
25 | //! ) |
26 | //! ) |
27 | //! ``` |
28 | //! |
29 | //! ## [`LineText`] |
30 | //! |
31 | //! It's used to override a border with a custom text. |
32 | //! |
33 | //! ### Example |
34 | //! |
35 | #![cfg_attr (feature = "std" , doc = "```" )] |
36 | #![cfg_attr (not(feature = "std" ), doc = "```ignore" )] |
37 | //! use tabled::{ |
38 | //! Table, settings::{style::{LineText, Style}, object::Rows}, |
39 | //! }; |
40 | //! |
41 | //! let data = vec!["Hello" , "2022" ]; |
42 | //! let table = Table::new(&data) |
43 | //! .with(Style::psql()) |
44 | //! .with(LineText::new("Santa" , Rows::single(1))) |
45 | //! .to_string(); |
46 | //! |
47 | //! assert_eq!( |
48 | //! table, |
49 | //! concat!( |
50 | //! " &str \n" , |
51 | //! "Santa-- \n" , |
52 | //! " Hello \n" , |
53 | //! " 2022 " , |
54 | //! ) |
55 | //! ) |
56 | //! ``` |
57 | //! |
58 | //! ## [`Border`] |
59 | //! |
60 | //! [`Border`] can be used to modify cell's borders. |
61 | //! |
62 | //! It's possible to set a collored border when `color` feature is on. |
63 | //! |
64 | //! ### Example |
65 | //! |
66 | #![cfg_attr (feature = "std" , doc = "```" )] |
67 | #![cfg_attr (not(feature = "std" ), doc = "```ignore" )] |
68 | //! use tabled::{Table, settings::{Modify, Style, style::Border}}; |
69 | //! |
70 | //! let data = vec!["Hello" , "2022" ]; |
71 | //! let table = Table::new(&data) |
72 | //! .with(Style::psql()) |
73 | //! .modify((0, 0), Border::inherit(Style::modern())) |
74 | //! .to_string(); |
75 | //! |
76 | //! assert_eq!( |
77 | //! table, |
78 | //! concat!( |
79 | //! "┌───────┐ \n" , |
80 | //! "│ &str │ \n" , |
81 | //! "└───────┘ \n" , |
82 | //! " Hello \n" , |
83 | //! " 2022 " , |
84 | //! ) |
85 | //! ) |
86 | //! ``` |
87 | //! |
88 | //! ## [`Theme`] |
89 | //! |
90 | //! A different representation of [`Theme`]. |
91 | //! With no checks in place. |
92 | //! |
93 | //! It also contains a list of types to support colors. |
94 | //! |
95 | //! [`Table`]: crate::Table |
96 | //! [`BorderText`]: crate::settings::style::BorderText |
97 | //! [`Theme`]: crate::settings::themes::Theme |
98 | |
99 | mod border; |
100 | mod builder; |
101 | mod horizontal_line; |
102 | mod offset; |
103 | mod vertical_line; |
104 | |
105 | #[cfg (feature = "std" )] |
106 | mod border_color; |
107 | #[cfg (feature = "std" )] |
108 | mod border_text; |
109 | #[cfg (feature = "std" )] |
110 | mod line_char; |
111 | #[cfg (feature = "std" )] |
112 | mod span_border_correction; |
113 | |
114 | #[cfg (feature = "std" )] |
115 | #[cfg_attr (docsrs, doc(cfg(feature = "std" )))] |
116 | pub use self::{ |
117 | border_color::BorderColor, border_text::LineText, line_char::LineChar, |
118 | span_border_correction::BorderSpanCorrection, |
119 | }; |
120 | |
121 | pub use self::{ |
122 | border::Border, |
123 | builder::{On, Style}, |
124 | horizontal_line::HorizontalLine, |
125 | offset::Offset, |
126 | vertical_line::VerticalLine, |
127 | }; |
128 | |
129 | use crate::grid::config::{Borders, CompactConfig, CompactMultilineConfig}; |
130 | use crate::settings::TableOption; |
131 | |
132 | #[cfg (feature = "std" )] |
133 | use crate::grid::config::ColoredConfig; |
134 | |
135 | #[cfg (feature = "std" )] |
136 | impl<R, D> TableOption<R, ColoredConfig, D> for Borders<char> { |
137 | fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D) { |
138 | cfg_clear_borders(cfg); |
139 | cfg.set_borders(self); |
140 | } |
141 | } |
142 | |
143 | impl<R, D> TableOption<R, CompactConfig, D> for Borders<char> { |
144 | fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) { |
145 | *cfg = cfg.set_borders(self); |
146 | } |
147 | } |
148 | |
149 | impl<R, D> TableOption<R, CompactMultilineConfig, D> for Borders<char> { |
150 | fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D) { |
151 | cfg.set_borders(self); |
152 | } |
153 | } |
154 | |
155 | #[cfg (feature = "std" )] |
156 | fn cfg_clear_borders(cfg: &mut ColoredConfig) { |
157 | cfg.remove_borders(); |
158 | cfg.remove_borders_colors(); |
159 | cfg.remove_vertical_chars(); |
160 | cfg.remove_horizontal_chars(); |
161 | cfg.remove_color_line_horizontal(); |
162 | cfg.remove_color_line_vertical(); |
163 | } |
164 | |