1use crate::grid::{
2 ansi::ANSIStr,
3 config::{
4 AlignmentHorizontal, AlignmentVertical, Borders, CompactConfig, Formatting, Indent, Sides,
5 },
6};
7
8/// A [`CompactConfig`] based configuration plus vertical alignment and formatting options.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
10pub struct CompactMultilineConfig {
11 config: CompactConfig,
12 alignment_vertical: AlignmentVertical,
13 formatting: Formatting,
14}
15
16impl CompactMultilineConfig {
17 /// Create a new [`CompactMultilineConfig`].
18 pub const fn new() -> Self {
19 Self {
20 config: CompactConfig::new(),
21 alignment_vertical: AlignmentVertical::Top,
22 formatting: Formatting::new(false, false, false),
23 }
24 }
25
26 /// Create a new [`CompactMultilineConfig`].
27 pub const fn from_compact(config: CompactConfig) -> Self {
28 Self {
29 config,
30 alignment_vertical: AlignmentVertical::Top,
31 formatting: Formatting::new(false, false, false),
32 }
33 }
34
35 /// Set a horizontal alignment.
36 pub fn set_alignment_vertical(&mut self, alignment: AlignmentVertical) {
37 self.alignment_vertical = alignment
38 }
39
40 /// Get a alignment horizontal.
41 pub const fn get_alignment_vertical(&self) -> AlignmentVertical {
42 self.alignment_vertical
43 }
44
45 /// Set grid margin.
46 pub fn set_margin(&mut self, margin: Sides<Indent>) {
47 self.config = self.config.set_margin(margin);
48 }
49
50 /// Returns a grid margin.
51 pub const fn get_margin(&self) -> &Sides<Indent> {
52 self.config.get_margin()
53 }
54
55 /// Set the [`Borders`] value as correct one.
56 pub fn set_borders(&mut self, borders: Borders<char>) {
57 self.config = self.config.set_borders(borders)
58 }
59
60 /// Returns a current [`Borders`] structure.
61 pub const fn get_borders(&self) -> &Borders<char> {
62 self.config.get_borders()
63 }
64
65 /// Returns a current [`Borders`] structure.
66 pub const fn get_borders_color(&self) -> &Borders<ANSIStr<'static>> {
67 self.config.get_borders_color()
68 }
69
70 /// Set a padding to a given cells.
71 pub fn set_padding(&mut self, padding: Sides<Indent>) {
72 self.config = self.config.set_padding(padding)
73 }
74
75 /// Get a padding for a given.
76 pub const fn get_padding(&self) -> &Sides<Indent> {
77 self.config.get_padding()
78 }
79
80 /// Set a horizontal alignment.
81 pub fn set_alignment_horizontal(&mut self, alignment: AlignmentHorizontal) {
82 self.config = self.config.set_alignment_horizontal(alignment)
83 }
84
85 /// Get a alignment horizontal.
86 pub const fn get_alignment_horizontal(&self) -> AlignmentHorizontal {
87 self.config.get_alignment_horizontal()
88 }
89
90 /// Sets colors of border carcass on the grid.
91 pub fn set_borders_color(&mut self, borders: Borders<ANSIStr<'static>>) {
92 self.config = self.config.set_borders_color(borders)
93 }
94
95 /// Set colors for a margin.
96 pub fn set_margin_color(&mut self, color: Sides<ANSIStr<'static>>) {
97 self.config = self.config.set_margin_color(color)
98 }
99
100 /// Returns a margin color.
101 pub const fn get_margin_color(&self) -> &Sides<ANSIStr<'static>> {
102 self.config.get_margin_color()
103 }
104
105 /// Set a padding color to all cells.
106 pub fn set_padding_color(&mut self, color: Sides<ANSIStr<'static>>) {
107 self.config = self.config.set_padding_color(color)
108 }
109
110 /// get a padding color.
111 pub const fn get_padding_color(&self) -> &Sides<ANSIStr<'static>> {
112 self.config.get_padding_color()
113 }
114
115 /// Set formatting.
116 pub fn set_formatting(&mut self, formatting: Formatting) {
117 self.formatting = formatting
118 }
119
120 /// Get formatting.
121 pub const fn get_formatting(&self) -> Formatting {
122 self.formatting
123 }
124}
125
126impl Default for CompactMultilineConfig {
127 fn default() -> Self {
128 Self {
129 config: Default::default(),
130 alignment_vertical: AlignmentVertical::Top,
131 formatting: Formatting::default(),
132 }
133 }
134}
135
136impl From<CompactMultilineConfig> for CompactConfig {
137 fn from(cfg: CompactMultilineConfig) -> Self {
138 cfg.config
139 }
140}
141
142impl From<CompactConfig> for CompactMultilineConfig {
143 fn from(config: CompactConfig) -> Self {
144 Self {
145 config,
146 alignment_vertical: AlignmentVertical::Top,
147 formatting: Formatting::default(),
148 }
149 }
150}
151
152#[cfg(feature = "std")]
153impl From<CompactMultilineConfig> for crate::grid::config::SpannedConfig {
154 fn from(compact: CompactMultilineConfig) -> Self {
155 use crate::grid::config::Entity::*;
156 use crate::grid::config::SpannedConfig;
157
158 let mut cfg: SpannedConfig = SpannedConfig::from(compact.config);
159 cfg.set_alignment_vertical(entity:Global, alignment:compact.alignment_vertical);
160 cfg.set_formatting(entity:Global, compact.formatting);
161
162 cfg
163 }
164}
165