1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use crate::grid::{
    ansi::ANSIStr,
    config::{
        AlignmentHorizontal, AlignmentVertical, Borders, CompactConfig, Formatting, Indent, Sides,
    },
};

/// A [`CompactConfig`] based configuration plus vertical alignment and formatting options.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct CompactMultilineConfig {
    config: CompactConfig,
    alignment_vertical: AlignmentVertical,
    formatting: Formatting,
}

impl CompactMultilineConfig {
    /// Create a new [`CompactMultilineConfig`].
    pub const fn new() -> Self {
        Self {
            config: CompactConfig::new(),
            alignment_vertical: AlignmentVertical::Top,
            formatting: Formatting::new(false, false, false),
        }
    }

    /// Create a new [`CompactMultilineConfig`].
    pub const fn from_compact(config: CompactConfig) -> Self {
        Self {
            config,
            alignment_vertical: AlignmentVertical::Top,
            formatting: Formatting::new(false, false, false),
        }
    }

    /// Set a horizontal alignment.
    pub fn set_alignment_vertical(&mut self, alignment: AlignmentVertical) {
        self.alignment_vertical = alignment
    }

    /// Get a alignment horizontal.
    pub const fn get_alignment_vertical(&self) -> AlignmentVertical {
        self.alignment_vertical
    }

    /// Set grid margin.
    pub fn set_margin(&mut self, margin: Sides<Indent>) {
        self.config = self.config.set_margin(margin);
    }

    /// Returns a grid margin.
    pub const fn get_margin(&self) -> &Sides<Indent> {
        self.config.get_margin()
    }

    /// Set the [`Borders`] value as correct one.
    pub fn set_borders(&mut self, borders: Borders<char>) {
        self.config = self.config.set_borders(borders)
    }

    /// Returns a current [`Borders`] structure.
    pub const fn get_borders(&self) -> &Borders<char> {
        self.config.get_borders()
    }

    /// Returns a current [`Borders`] structure.
    pub const fn get_borders_color(&self) -> &Borders<ANSIStr<'static>> {
        self.config.get_borders_color()
    }

    /// Set a padding to a given cells.
    pub fn set_padding(&mut self, padding: Sides<Indent>) {
        self.config = self.config.set_padding(padding)
    }

    /// Get a padding for a given.
    pub const fn get_padding(&self) -> &Sides<Indent> {
        self.config.get_padding()
    }

    /// Set a horizontal alignment.
    pub fn set_alignment_horizontal(&mut self, alignment: AlignmentHorizontal) {
        self.config = self.config.set_alignment_horizontal(alignment)
    }

    /// Get a alignment horizontal.
    pub const fn get_alignment_horizontal(&self) -> AlignmentHorizontal {
        self.config.get_alignment_horizontal()
    }

    /// Sets colors of border carcass on the grid.
    pub fn set_borders_color(&mut self, borders: Borders<ANSIStr<'static>>) {
        self.config = self.config.set_borders_color(borders)
    }

    /// Set colors for a margin.
    pub fn set_margin_color(&mut self, color: Sides<ANSIStr<'static>>) {
        self.config = self.config.set_margin_color(color)
    }

    /// Returns a margin color.
    pub const fn get_margin_color(&self) -> &Sides<ANSIStr<'static>> {
        self.config.get_margin_color()
    }

    /// Set a padding color to all cells.
    pub fn set_padding_color(&mut self, color: Sides<ANSIStr<'static>>) {
        self.config = self.config.set_padding_color(color)
    }

    /// get a padding color.
    pub const fn get_padding_color(&self) -> &Sides<ANSIStr<'static>> {
        self.config.get_padding_color()
    }

    /// Set formatting.
    pub fn set_formatting(&mut self, formatting: Formatting) {
        self.formatting = formatting
    }

    /// Get formatting.
    pub const fn get_formatting(&self) -> Formatting {
        self.formatting
    }
}

impl Default for CompactMultilineConfig {
    fn default() -> Self {
        Self {
            config: Default::default(),
            alignment_vertical: AlignmentVertical::Top,
            formatting: Formatting::default(),
        }
    }
}

impl From<CompactMultilineConfig> for CompactConfig {
    fn from(cfg: CompactMultilineConfig) -> Self {
        cfg.config
    }
}

impl From<CompactConfig> for CompactMultilineConfig {
    fn from(config: CompactConfig) -> Self {
        Self {
            config,
            alignment_vertical: AlignmentVertical::Top,
            formatting: Formatting::default(),
        }
    }
}

#[cfg(feature = "std")]
impl From<CompactMultilineConfig> for crate::grid::config::SpannedConfig {
    fn from(compact: CompactMultilineConfig) -> Self {
        use crate::grid::config::Entity::*;
        use crate::grid::config::SpannedConfig;

        let mut cfg = SpannedConfig::from(compact.config);
        cfg.set_alignment_vertical(Global, compact.alignment_vertical);
        cfg.set_formatting(Global, compact.formatting);

        cfg
    }
}