lexa_logger/layout/
style.rs1pub const STYLE_BLANK: Style = Style {
16 top: CornerStyle::all('\0'),
17 bottom: CornerStyle::all('\0'),
18
19 left: '\0',
20 right: '\0',
21
22 intersection: '\0',
23 vertical: '\0',
24 horizontal: '\0',
25};
26
27pub const STYLE_ROUNDED: Style = Style {
28 top: CornerStyle {
29 left: '╭',
30 right: '╮',
31 intersection: '┬',
32 },
33
34 bottom: CornerStyle {
35 left: '╰',
36 right: '╯',
37 intersection: '┴',
38 },
39
40 left: '├',
41 right: '┤',
42
43 vertical: '│',
44 horizontal: '─',
45 intersection: '┼',
46};
47
48pub const STYLE_SIMPLE: Style = Style {
49 top: CornerStyle::all('+'),
50 bottom: CornerStyle::all('+'),
51
52 left: '+',
53 right: '+',
54
55 intersection: '+',
56 vertical: '|',
57 horizontal: '-',
58};
59
60pub const STYLE_THIN: Style = Style {
61 top: CornerStyle {
62 left: '┌',
63 right: '┐',
64 intersection: '┬',
65 },
66 bottom: CornerStyle {
67 left: '└',
68 right: '┘',
69 intersection: '┴',
70 },
71
72 left: '├',
73 right: '┤',
74
75 vertical: '│',
76 horizontal: '─',
77 intersection: '┼',
78};
79
80#[derive(Debug)]
85#[derive(Clone, Copy)]
86pub struct Style
87{
88 top: CornerStyle,
89 pub(crate) right: char,
90 bottom: CornerStyle,
91 pub(crate) left: char,
92
93 pub(crate) vertical: char,
94 pub(crate) horizontal: char,
95 pub(crate) intersection: char,
96}
97
98#[derive(Debug)]
99#[derive(Clone, Copy)]
100pub struct CornerStyle
101{
102 left: char,
103 right: char,
104 intersection: char,
105}
106
107#[derive(Debug)]
112#[derive(Copy, Clone)]
113#[derive(Eq, PartialEq)]
114pub enum Alignment
115{
116 Left,
117 Right,
118 Center,
119}
120
121#[derive(Copy, Clone)]
122#[derive(Eq, PartialEq)]
123pub(crate) enum Position
124{
125 First,
126 Middle,
127 Last,
128}
129
130impl Style
135{
136 pub(crate) const fn start_position(&self, position: Position) -> char
137 {
138 match position {
139 | Position::First => self.top.left,
140 | Position::Middle => self.left,
141 | Position::Last => self.bottom.left,
142 }
143 }
144
145 pub(crate) const fn end_position(&self, position: Position) -> char
146 {
147 match position {
148 | Position::First => self.top.right,
149 | Position::Middle => self.right,
150 | Position::Last => self.bottom.right,
151 }
152 }
153
154 pub(crate) const fn intersect_position(&self, position: Position) -> char
155 {
156 match position {
157 | Position::First => self.top.intersection,
158 | Position::Middle => self.intersection,
159 | Position::Last => self.bottom.intersection,
160 }
161 }
162
163 pub(crate) const fn merge_intersection_position(&self, top: char, bottom: char, position: Position) -> char
164 {
165 if (top == self.horizontal || top == self.bottom.intersection) && bottom == self.intersection {
166 self.top.intersection
167 } else if (top == self.intersection || top == self.top.intersection) && bottom == self.horizontal {
168 self.bottom.intersection
169 } else if top == self.bottom.intersection && bottom == self.horizontal {
170 self.horizontal
171 } else {
172 self.intersect_position(position)
173 }
174 }
175}
176
177impl CornerStyle
178{
179 const fn all(ch: char) -> Self
180 {
181 Self {
182 left: ch,
183 right: ch,
184 intersection: ch,
185 }
186 }
187}