1+ use std:: fmt;
2+
3+ use crate :: formatter:: { get_term_style, style:: Stylesheet } ;
4+
15/// List of lines to be displayed.
2- #[ derive( Debug , Clone , PartialEq ) ]
36pub struct DisplayList {
47pub body : Vec < DisplayLine > ,
8+ pub stylesheet : Box < dyn Stylesheet > ,
9+ pub anonymized_line_numbers : bool ,
510}
611
712impl From < Vec < DisplayLine > > for DisplayList {
813fn 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
1025}
1126}
1227
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+
1343/// Inline annotation which can be used in either Raw or Source line.
1444#[ derive( Debug , Clone , PartialEq ) ]
1545pub struct Annotation {
@@ -125,63 +155,8 @@ pub struct DisplayMark {
125155#[ derive( Debug , Clone , PartialEq ) ]
126156pub enum DisplayMarkType {
127157/// 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- /// ```
155158AnnotationThrough ,
156-
157159/// 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- /// ```
185160AnnotationStart ,
186161}
187162
@@ -205,49 +180,12 @@ pub enum DisplayAnnotationType {
205180
206181/// Information whether the header is the initial one or a consequitive one
207182/// for multi-slice cases.
183+ // TODO: private
208184#[ derive( Debug , Clone , PartialEq ) ]
209185pub enum DisplayHeaderType {
210186/// 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- /// ```
230187Initial ,
231188
232189/// 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- /// ```
252190Continuation ,
253191}