tabled/settings/style/
mod.rs

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::one(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
99mod border;
100mod builder;
101mod horizontal_line;
102mod vertical_line;
103
104#[cfg(feature = "std")]
105mod border_color;
106#[cfg(feature = "std")]
107mod line_char;
108#[cfg(feature = "std")]
109mod line_text;
110
111#[cfg(feature = "std")]
112#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
113pub use self::{border_color::BorderColor, line_char::LineChar, line_text::LineText};
114
115pub use self::{
116    border::Border,
117    builder::{On, Style},
118    horizontal_line::HorizontalLine,
119    vertical_line::VerticalLine,
120};
121
122use crate::grid::config::{Borders, CompactConfig, CompactMultilineConfig};
123use crate::settings::TableOption;
124
125#[cfg(feature = "std")]
126use crate::grid::config::ColoredConfig;
127
128#[cfg(feature = "std")]
129impl<R, D> TableOption<R, ColoredConfig, D> for Borders<char> {
130    fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D) {
131        cfg_clear_borders(cfg);
132        cfg.set_borders(self);
133    }
134}
135
136impl<R, D> TableOption<R, CompactConfig, D> for Borders<char> {
137    fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
138        *cfg = cfg.set_borders(self);
139    }
140}
141
142impl<R, D> TableOption<R, CompactMultilineConfig, D> for Borders<char> {
143    fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D) {
144        cfg.set_borders(self);
145    }
146}
147
148#[cfg(feature = "std")]
149fn cfg_clear_borders(cfg: &mut ColoredConfig) {
150    cfg.remove_borders();
151    cfg.remove_borders_colors();
152    cfg.remove_vertical_chars();
153    cfg.remove_horizontal_chars();
154    cfg.remove_color_line_horizontal();
155    cfg.remove_color_line_vertical();
156}