tabled/settings/margin_color/
mod.rs1use crate::{
6 grid::{
7 ansi::ANSIStr,
8 config::Sides,
9 config::{CompactConfig, CompactMultilineConfig},
10 },
11 settings::TableOption,
12};
13
14#[cfg(feature = "std")]
15use crate::grid::{ansi::ANSIBuf, config::ColoredConfig};
16
17#[cfg_attr(feature = "ansi", doc = "```")]
22#[cfg_attr(not(feature = "ansi"), doc = "```ignore")]
23#[derive(Debug, Clone)]
49pub struct MarginColor<C> {
50 colors: Sides<C>,
51}
52
53impl<C> MarginColor<C> {
54 pub const fn new(left: C, right: C, top: C, bottom: C) -> Self {
56 Self {
57 colors: Sides::new(left, right, top, bottom),
58 }
59 }
60
61 pub fn filled(color: C) -> Self
63 where
64 C: Clone,
65 {
66 Self::new(color.clone(), color.clone(), color.clone(), color)
67 }
68}
69
70impl MarginColor<ANSIStr<'static>> {
71 pub const fn empty() -> Self {
73 Self::new(
74 ANSIStr::empty(),
75 ANSIStr::empty(),
76 ANSIStr::empty(),
77 ANSIStr::empty(),
78 )
79 }
80}
81
82#[cfg(feature = "std")]
83impl<R, D, C> TableOption<R, ColoredConfig, D> for MarginColor<C>
84where
85 C: Into<ANSIBuf> + Clone,
86{
87 fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D) {
88 let c = self.colors.clone();
89 let margin = Sides::new(
90 Some(c.left.into()),
91 Some(c.right.into()),
92 Some(c.top.into()),
93 Some(c.bottom.into()),
94 );
95
96 cfg.set_margin_color(margin);
97 }
98}
99
100impl<R, D, C> TableOption<R, CompactConfig, D> for MarginColor<C>
101where
102 C: Into<ANSIStr<'static>> + Clone,
103{
104 fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
105 let colors = self.colors.convert_into();
106 *cfg = cfg.set_margin_color(colors);
107 }
108}
109
110impl<R, D, C> TableOption<R, CompactMultilineConfig, D> for MarginColor<C>
111where
112 C: Into<ANSIStr<'static>> + Clone,
113{
114 fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D) {
115 let colors = self.colors.convert_into();
116 cfg.set_margin_color(colors);
117 }
118}