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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#[derive(Debug)]
pub struct VerticalLine {
pub(crate) filler: char,
}
impl Default for VerticalLine {
fn default() -> Self {
Self { filler: '|' }
}
}
impl VerticalLine {
pub fn new(filler: char) -> Self {
Self { filler }
}
}
#[derive(Debug)]
pub struct HorizontalLine {
pub(crate) left_end: char,
pub(crate) right_end: char,
pub(crate) junction: char,
pub(crate) filler: char,
}
impl Default for HorizontalLine {
fn default() -> Self {
Self {
left_end: '+',
right_end: '+',
junction: '+',
filler: '-',
}
}
}
impl HorizontalLine {
pub fn new(left_end: char, right_end: char, junction: char, filler: char) -> Self {
Self {
left_end,
right_end,
junction,
filler,
}
}
}
#[derive(Debug)]
pub struct Border {
pub(crate) top: Option<HorizontalLine>,
pub(crate) bottom: Option<HorizontalLine>,
pub(crate) left: Option<VerticalLine>,
pub(crate) right: Option<VerticalLine>,
}
impl Border {
pub fn builder() -> BorderBuilder {
BorderBuilder(Border {
top: None,
bottom: None,
left: None,
right: None,
})
}
}
impl Default for Border {
fn default() -> Self {
Self {
top: Some(Default::default()),
bottom: Some(Default::default()),
left: Some(Default::default()),
right: Some(Default::default()),
}
}
}
#[derive(Debug)]
pub struct BorderBuilder(Border);
impl BorderBuilder {
pub fn top(mut self, top: Option<HorizontalLine>) -> Self {
self.0.top = top;
self
}
pub fn bottom(mut self, bottom: Option<HorizontalLine>) -> Self {
self.0.bottom = bottom;
self
}
pub fn left(mut self, left: Option<VerticalLine>) -> Self {
self.0.left = left;
self
}
pub fn right(mut self, right: Option<VerticalLine>) -> Self {
self.0.right = right;
self
}
pub fn build(self) -> Border {
self.0
}
}
#[derive(Debug)]
pub struct Separator {
pub(crate) column: Option<VerticalLine>,
pub(crate) row: Option<HorizontalLine>,
pub(crate) title: Option<HorizontalLine>,
}
impl Separator {
pub fn builder() -> SeparatorBuilder {
SeparatorBuilder(Separator {
column: None,
row: None,
title: None,
})
}
}
impl Default for Separator {
fn default() -> Self {
Self {
column: Some(Default::default()),
row: Some(Default::default()),
title: None,
}
}
}
#[derive(Debug)]
pub struct SeparatorBuilder(Separator);
impl SeparatorBuilder {
pub fn column(mut self, column: Option<VerticalLine>) -> Self {
self.0.column = column;
self
}
pub fn row(mut self, row: Option<HorizontalLine>) -> Self {
self.0.row = row;
self
}
pub fn title(mut self, title: Option<HorizontalLine>) -> Self {
self.0.title = title;
self
}
pub fn build(self) -> Separator {
self.0
}
}
#[derive(Debug, Default)]
pub struct TableFormat {
pub(crate) border: Border,
pub(crate) separator: Separator,
}
impl TableFormat {
pub fn new(border: Border, separator: Separator) -> Self {
Self { border, separator }
}
}