comfy_table/style/
table_style.rs1#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
18pub struct LineStyle {
19 pub left: Option<char>,
20 pub fill: Option<char>,
21 pub junction: Option<char>,
22 pub right: Option<char>,
23}
24
25impl LineStyle {
26 pub const fn new(left: char, fill: char, junction: char, right: char) -> Self {
28 Self {
29 left: Some(left),
30 fill: Some(fill),
31 junction: Some(junction),
32 right: Some(right),
33 }
34 }
35
36 pub const fn none() -> Self {
38 Self {
39 left: None,
40 fill: None,
41 junction: None,
42 right: None,
43 }
44 }
45
46 pub const fn left(mut self, character: char) -> Self {
48 self.left = Some(character);
49 self
50 }
51
52 pub const fn fill(mut self, character: char) -> Self {
54 self.fill = Some(character);
55 self
56 }
57
58 pub const fn junction(mut self, character: char) -> Self {
60 self.junction = Some(character);
61 self
62 }
63
64 pub const fn right(mut self, character: char) -> Self {
66 self.right = Some(character);
67 self
68 }
69
70 pub(crate) const fn is_visible(&self) -> bool {
71 self.left.is_some()
72 || self.fill.is_some()
73 || self.junction.is_some()
74 || self.right.is_some()
75 }
76}
77
78#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
93pub struct ContentLineStyle {
94 pub left: Option<char>,
95 pub junction: Option<char>,
96 pub right: Option<char>,
97}
98
99impl ContentLineStyle {
100 pub const fn new(left: char, junction: char, right: char) -> Self {
102 Self {
103 left: Some(left),
104 junction: Some(junction),
105 right: Some(right),
106 }
107 }
108
109 pub const fn none() -> Self {
111 Self {
112 left: None,
113 junction: None,
114 right: None,
115 }
116 }
117
118 pub const fn left(mut self, character: char) -> Self {
120 self.left = Some(character);
121 self
122 }
123
124 pub const fn junction(mut self, character: char) -> Self {
126 self.junction = Some(character);
127 self
128 }
129
130 pub const fn right(mut self, character: char) -> Self {
132 self.right = Some(character);
133 self
134 }
135}
136
137#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
167pub struct TableStyle {
168 pub top_border: LineStyle,
169 pub header_lines: ContentLineStyle,
170 pub header_separator: LineStyle,
171 pub content_lines: ContentLineStyle,
172 pub row_separator: LineStyle,
173 pub bottom_border: LineStyle,
174 pub top_inline_border: LineStyle,
175 pub bottom_inline_border: LineStyle,
176}
177
178impl TableStyle {
179 pub const fn new() -> Self {
181 Self {
182 top_border: LineStyle::none(),
183 header_lines: ContentLineStyle::none(),
184 header_separator: LineStyle::none(),
185 content_lines: ContentLineStyle::none(),
186 row_separator: LineStyle::none(),
187 bottom_border: LineStyle::none(),
188 top_inline_border: LineStyle::none(),
189 bottom_inline_border: LineStyle::none(),
190 }
191 }
192
193 pub const fn top_border(mut self, line: LineStyle) -> Self {
195 self.top_border = line;
196 self
197 }
198
199 pub const fn header_lines(mut self, line: ContentLineStyle) -> Self {
201 self.header_lines = line;
202 self
203 }
204
205 pub const fn header_separator(mut self, line: LineStyle) -> Self {
207 self.header_separator = line;
208 self
209 }
210
211 pub const fn content_lines(mut self, line: ContentLineStyle) -> Self {
213 self.content_lines = line;
214 self
215 }
216
217 pub const fn row_separator(mut self, line: LineStyle) -> Self {
219 self.row_separator = line;
220 self
221 }
222
223 pub const fn bottom_border(mut self, line: LineStyle) -> Self {
225 self.bottom_border = line;
226 self
227 }
228
229 pub const fn top_inline_border(mut self, line: LineStyle) -> Self {
231 self.top_inline_border = line;
232 self
233 }
234
235 pub const fn bottom_inline_border(mut self, line: LineStyle) -> Self {
237 self.bottom_inline_border = line;
238 self
239 }
240
241 pub const fn with_rounded_corners(mut self) -> Self {
252 self.top_border.left = Some('╭');
253 self.top_border.right = Some('╮');
254 self.bottom_border.left = Some('╰');
255 self.bottom_border.right = Some('╯');
256 self
257 }
258
259 pub const fn with_solid_inner_borders(mut self) -> Self {
270 self.header_lines.junction = Some('│');
271 self.content_lines.junction = Some('│');
272 self.row_separator.fill = Some('─');
273 self
274 }
275
276 pub(crate) const fn has_top_border(&self) -> bool {
277 self.top_border.is_visible()
278 }
279
280 pub(crate) const fn has_bottom_border(&self) -> bool {
281 self.bottom_border.is_visible()
282 }
283
284 pub(crate) const fn has_header_separator(&self) -> bool {
285 self.header_separator.is_visible()
286 }
287
288 pub(crate) const fn has_row_separator(&self) -> bool {
289 self.row_separator.is_visible()
290 }
291
292 pub(crate) const fn has_top_inline_border(&self) -> bool {
293 self.top_inline_border.is_visible()
294 }
295
296 pub(crate) const fn has_bottom_inline_border(&self) -> bool {
297 self.bottom_inline_border.is_visible()
298 }
299
300 pub(crate) const fn has_left_border(&self) -> bool {
302 self.header_lines.left.is_some()
303 || self.content_lines.left.is_some()
304 || self.top_border.left.is_some()
305 || self.header_separator.left.is_some()
306 || self.row_separator.left.is_some()
307 || self.bottom_border.left.is_some()
308 }
309
310 pub(crate) const fn has_right_border(&self) -> bool {
312 self.header_lines.right.is_some()
313 || self.content_lines.right.is_some()
314 || self.top_border.right.is_some()
315 || self.header_separator.right.is_some()
316 || self.row_separator.right.is_some()
317 || self.bottom_border.right.is_some()
318 }
319
320 pub(crate) const fn has_vertical_lines(&self) -> bool {
322 self.header_lines.junction.is_some()
323 || self.content_lines.junction.is_some()
324 || self.top_border.junction.is_some()
325 || self.header_separator.junction.is_some()
326 || self.row_separator.junction.is_some()
327 || self.bottom_border.junction.is_some()
328 }
329}