1
+ use std:: fmt;
2
+
3
+ use crate :: formatter:: { get_term_style, style:: Stylesheet } ;
4
+
1
5
/// List of lines to be displayed.
2
- #[ derive( Debug , Clone , PartialEq ) ]
3
6
pub struct DisplayList {
4
7
pub body : Vec < DisplayLine > ,
8
+ pub stylesheet : Box < dyn Stylesheet > ,
9
+ pub anonymized_line_numbers : bool ,
5
10
}
6
11
7
12
impl From < Vec < DisplayLine > > for DisplayList {
8
13
fn from ( body : Vec < DisplayLine > ) -> Self {
9
- Self { body }
14
+ Self {
15
+ body,
16
+ anonymized_line_numbers : false ,
17
+ stylesheet : get_term_style ( false ) ,
18
+ }
19
+ }
20
+ }
21
+
22
+ impl PartialEq for DisplayList {
23
+ fn eq ( & self , other : & Self ) -> bool {
24
+ self . body == other. body && self . anonymized_line_numbers == other. anonymized_line_numbers
10
25
}
11
26
}
12
27
28
+ impl fmt:: Debug for DisplayList {
29
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
30
+ f. debug_struct ( "DisplayList" )
31
+ . field ( "body" , & self . body )
32
+ . field ( "anonymized_line_numbers" , & self . anonymized_line_numbers )
33
+ . finish ( )
34
+ }
35
+ }
36
+
37
+ #[ derive( Debug , Default , Copy , Clone ) ]
38
+ pub struct FormatOptions {
39
+ pub color : bool ,
40
+ pub anonymized_line_numbers : bool ,
41
+ }
42
+
13
43
/// Inline annotation which can be used in either Raw or Source line.
14
44
#[ derive( Debug , Clone , PartialEq ) ]
15
45
pub struct Annotation {
@@ -125,63 +155,8 @@ pub struct DisplayMark {
125
155
#[ derive( Debug , Clone , PartialEq ) ]
126
156
pub enum DisplayMarkType {
127
157
/// A mark indicating a multiline annotation going through the current line.
128
- ///
129
- /// Example:
130
- /// ```
131
- /// use annotate_snippets::display_list::*;
132
- /// use annotate_snippets::formatter::DisplayListFormatter;
133
- ///
134
- /// let dlf = DisplayListFormatter::new(false, false); // Don't use colors
135
- ///
136
- /// let dl = DisplayList {
137
- /// body: vec![
138
- /// DisplayLine::Source {
139
- /// lineno: Some(51),
140
- /// inline_marks: vec![
141
- /// DisplayMark {
142
- /// mark_type: DisplayMarkType::AnnotationThrough,
143
- /// annotation_type: DisplayAnnotationType::Error,
144
- /// }
145
- /// ],
146
- /// line: DisplaySourceLine::Content {
147
- /// text: "Example".to_string(),
148
- /// range: (0, 7),
149
- /// }
150
- /// }
151
- /// ]
152
- /// };
153
- /// assert_eq!(dlf.format(&dl), "51 | | Example");
154
- /// ```
155
158
AnnotationThrough ,
156
-
157
159
/// A mark indicating a multiline annotation starting on the given line.
158
- ///
159
- /// Example:
160
- /// ```
161
- /// use annotate_snippets::display_list::*;
162
- /// use annotate_snippets::formatter::DisplayListFormatter;
163
- ///
164
- /// let dlf = DisplayListFormatter::new(false, false); // Don't use colors
165
- ///
166
- /// let dl = DisplayList {
167
- /// body: vec![
168
- /// DisplayLine::Source {
169
- /// lineno: Some(51),
170
- /// inline_marks: vec![
171
- /// DisplayMark {
172
- /// mark_type: DisplayMarkType::AnnotationStart,
173
- /// annotation_type: DisplayAnnotationType::Error,
174
- /// }
175
- /// ],
176
- /// line: DisplaySourceLine::Content {
177
- /// text: "Example".to_string(),
178
- /// range: (0, 7),
179
- /// }
180
- /// }
181
- /// ]
182
- /// };
183
- /// assert_eq!(dlf.format(&dl), "51 | / Example");
184
- /// ```
185
160
AnnotationStart ,
186
161
}
187
162
@@ -205,49 +180,12 @@ pub enum DisplayAnnotationType {
205
180
206
181
/// Information whether the header is the initial one or a consequitive one
207
182
/// for multi-slice cases.
183
+ // TODO: private
208
184
#[ derive( Debug , Clone , PartialEq ) ]
209
185
pub enum DisplayHeaderType {
210
186
/// Initial header is the first header in the snippet.
211
- ///
212
- /// Example:
213
- /// ```
214
- /// use annotate_snippets::display_list::*;
215
- /// use annotate_snippets::formatter::DisplayListFormatter;
216
- ///
217
- /// let dlf = DisplayListFormatter::new(false, false); // Don't use colors
218
- ///
219
- /// let dl = DisplayList {
220
- /// body: vec![
221
- /// DisplayLine::Raw(DisplayRawLine::Origin {
222
- /// path: "file1.rs".to_string(),
223
- /// pos: Some((51, 5)),
224
- /// header_type: DisplayHeaderType::Initial,
225
- /// })
226
- /// ]
227
- /// };
228
- /// assert_eq!(dlf.format(&dl), "--> file1.rs:51:5");
229
- /// ```
230
187
Initial ,
231
188
232
189
/// Continuation marks all headers of following slices in the snippet.
233
- ///
234
- /// Example:
235
- /// ```
236
- /// use annotate_snippets::display_list::*;
237
- /// use annotate_snippets::formatter::DisplayListFormatter;
238
- ///
239
- /// let dlf = DisplayListFormatter::new(false, false); // Don't use colors
240
- ///
241
- /// let dl = DisplayList {
242
- /// body: vec![
243
- /// DisplayLine::Raw(DisplayRawLine::Origin {
244
- /// path: "file1.rs".to_string(),
245
- /// pos: Some((51, 5)),
246
- /// header_type: DisplayHeaderType::Continuation,
247
- /// })
248
- /// ]
249
- /// };
250
- /// assert_eq!(dlf.format(&dl), "::: file1.rs:51:5");
251
- /// ```
252
190
Continuation ,
253
191
}
0 commit comments