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
194
195
196
197
198
199
200
201
202
203
204
205
206
/// A struct that contains the characters used to draw a table.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Style {
/// The character used for a top-left corner.
pub top_left_corner: char,
/// The character used for a top-right corner.
pub top_right_corner: char,
/// The character used for a bottom-left corner.
pub bottom_left_corner: char,
/// The character used for a bottom-right corner.
pub bottom_right_corner: char,
/// The character used for a vertical line with a right intersection.
pub outer_left_vertical: char,
/// The character used for a vertical line with a left intersection.
pub outer_right_vertical: char,
/// The character used for a horizontal line with a top intesection.
pub outer_bottom_horizontal: char,
/// The character used for a horizontal line with a bottom intersection.
pub outer_top_horizontal: char,
/// The character used for an four-way intersection of lines.
pub intersection: char,
/// The character used for a vertical line.
pub vertical: char,
/// The character used for a horizontal line.
pub horizontal: char,
}
impl Style {
/// A simple plain ASCII table style.
///
/// <pre>
/// +---------------------------------------------------------------------------------+
/// | This is some centered text |
/// +----------------------------------------+----------------------------------------+
/// | This is left aligned text | This is right aligned text |
/// +----------------------------------------+----------------------------------------+
/// | This is left aligned text | This is right aligned text |
/// +----------------------------------------+----------------------------------------+
/// | This is some really really really really really really really really really tha |
/// | t is going to wrap to the next line |
/// +---------------------------------------------------------------------------------+
/// </pre>
pub fn ascii() -> Style {
Style {
top_left_corner: '+',
top_right_corner: '+',
bottom_left_corner: '+',
bottom_right_corner: '+',
outer_left_vertical: '+',
outer_right_vertical: '+',
outer_bottom_horizontal: '+',
outer_top_horizontal: '+',
intersection: '+',
vertical: '|',
horizontal: '-',
}
}
/// A heavy table style with double lines.
///
/// <pre>
/// ╔═════════════════════════════════════════════════════════════════════════════════╗
/// ║ This is some centered text ║
/// ╠════════════════════════════════════════╦════════════════════════════════════════╣
/// ║ This is left aligned text ║ This is right aligned text ║
/// ╠════════════════════════════════════════╬════════════════════════════════════════╣
/// ║ This is left aligned text ║ This is right aligned text ║
/// ╠════════════════════════════════════════╩════════════════════════════════════════╣
/// ║ This is some really really really really really really really really really tha ║
/// ║ t is going to wrap to the next line ║
/// ╚═════════════════════════════════════════════════════════════════════════════════╝
/// </pre>
pub fn heavy() -> Style {
Style {
top_left_corner: '╔',
top_right_corner: '╗',
bottom_left_corner: '╚',
bottom_right_corner: '╝',
outer_left_vertical: '╠',
outer_right_vertical: '╣',
outer_bottom_horizontal: '╩',
outer_top_horizontal: '╦',
intersection: '╬',
vertical: '║',
horizontal: '═',
}
}
/// A thin table style with single lines.
///
/// <pre>
/// ┌─────────────────────────────────────────────────────────────────────────────────┐
/// │ This is some centered text │
/// ├────────────────────────────────────────┬────────────────────────────────────────┤
/// │ This is left aligned text │ This is right aligned text │
/// ├────────────────────────────────────────┼────────────────────────────────────────┤
/// │ This is left aligned text │ This is right aligned text │
/// ├────────────────────────────────────────┴────────────────────────────────────────┤
/// │ This is some really really really really really really really really really tha │
/// │ t is going to wrap to the next line │
/// └─────────────────────────────────────────────────────────────────────────────────┘
/// </pre>
pub fn thin() -> Style {
Style {
top_left_corner: '┌',
top_right_corner: '┐',
bottom_left_corner: '└',
bottom_right_corner: '┘',
outer_left_vertical: '├',
outer_right_vertical: '┤',
outer_bottom_horizontal: '┴',
outer_top_horizontal: '┬',
intersection: '┼',
vertical: '│',
horizontal: '─',
}
}
/// A thin table style with single lines and rounded corners.
///
/// <pre>
/// ╭─────────────────────────────────────────────────────────────────────────────────╮
/// │ This is some centered text │
/// ├────────────────────────────────────────┬────────────────────────────────────────┤
/// │ This is left aligned text │ This is right aligned text │
/// ├────────────────────────────────────────┼────────────────────────────────────────┤
/// │ This is left aligned text │ This is right aligned text │
/// ├────────────────────────────────────────┴────────────────────────────────────────┤
/// │ This is some really really really really really really really really really tha │
/// │ t is going to wrap to the next line │
/// ╰─────────────────────────────────────────────────────────────────────────────────╯
/// </pre>
pub fn rounded() -> Style {
Style {
top_left_corner: '╭',
top_right_corner: '╮',
bottom_left_corner: '╰',
bottom_right_corner: '╯',
outer_left_vertical: '├',
outer_right_vertical: '┤',
outer_bottom_horizontal: '┴',
outer_top_horizontal: '┬',
intersection: '┼',
vertical: '│',
horizontal: '─',
}
}
/// A fancy table style with thin lines and prononced corners.
///
/// <pre>
/// ╔─────────────────────────────────────────────────────────────────────────────────╗
/// │ This is some centered text │
/// ╠────────────────────────────────────────╦────────────────────────────────────────╣
/// │ This is left aligned text │ This is right aligned text │
/// ╠────────────────────────────────────────┼────────────────────────────────────────╣
/// │ This is left aligned text │ This is right aligned text │
/// ╠────────────────────────────────────────╩────────────────────────────────────────╣
/// │ This is some really really really really really really really really really tha │
/// │ t is going to wrap to the next line │
/// ╚─────────────────────────────────────────────────────────────────────────────────╝
/// </pre>
pub fn fancy() -> Style {
Style {
top_left_corner: '╔',
top_right_corner: '╗',
bottom_left_corner: '╚',
bottom_right_corner: '╝',
outer_left_vertical: '╠',
outer_right_vertical: '╣',
outer_bottom_horizontal: '╩',
outer_top_horizontal: '╦',
intersection: '┼',
vertical: '│',
horizontal: '─',
}
}
/// A table style that does not draw any lines (using spaces).
///
///<pre>
/// This is some centered text
///
/// This is left aligned text This is right aligned text
///
/// This is left aligned text This is right aligned text
///
/// This is some really really really really really really really really really tha
/// t is going to wrap to the next line
///</pre>
pub fn empty() -> Style {
Style {
top_left_corner: ' ',
top_right_corner: ' ',
bottom_left_corner: ' ',
bottom_right_corner: ' ',
outer_left_vertical: ' ',
outer_right_vertical: ' ',
outer_bottom_horizontal: ' ',
outer_top_horizontal: ' ',
intersection: ' ',
vertical: ' ',
horizontal: ' ',
}
}
}