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
use std::fmt;
use crate::formatter::{get_term_style, style::Stylesheet};
pub struct DisplayList<'a> {
pub body: Vec<DisplayLine<'a>>,
pub stylesheet: Box<dyn Stylesheet>,
pub anonymized_line_numbers: bool,
}
impl<'a> From<Vec<DisplayLine<'a>>> for DisplayList<'a> {
fn from(body: Vec<DisplayLine<'a>>) -> DisplayList<'a> {
Self {
body,
anonymized_line_numbers: false,
stylesheet: get_term_style(false),
}
}
}
impl<'a> PartialEq for DisplayList<'a> {
fn eq(&self, other: &Self) -> bool {
self.body == other.body && self.anonymized_line_numbers == other.anonymized_line_numbers
}
}
impl<'a> fmt::Debug for DisplayList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DisplayList")
.field("body", &self.body)
.field("anonymized_line_numbers", &self.anonymized_line_numbers)
.finish()
}
}
#[derive(Debug, Default, Copy, Clone)]
pub struct FormatOptions {
pub color: bool,
pub anonymized_line_numbers: bool,
}
#[derive(Debug, PartialEq)]
pub struct Annotation<'a> {
pub annotation_type: DisplayAnnotationType,
pub id: Option<&'a str>,
pub label: Vec<DisplayTextFragment<'a>>,
}
#[derive(Debug, PartialEq)]
pub enum DisplayLine<'a> {
Source {
lineno: Option<usize>,
inline_marks: Vec<DisplayMark>,
line: DisplaySourceLine<'a>,
},
Fold { inline_marks: Vec<DisplayMark> },
Raw(DisplayRawLine<'a>),
}
#[derive(Debug, PartialEq)]
pub enum DisplaySourceLine<'a> {
Content {
text: &'a str,
range: (usize, usize),
},
Annotation {
annotation: Annotation<'a>,
range: (usize, usize),
annotation_type: DisplayAnnotationType,
annotation_part: DisplayAnnotationPart,
},
Empty,
}
#[derive(Debug, PartialEq)]
pub enum DisplayRawLine<'a> {
Origin {
path: &'a str,
pos: Option<(usize, usize)>,
header_type: DisplayHeaderType,
},
Annotation {
annotation: Annotation<'a>,
source_aligned: bool,
continuation: bool,
},
}
#[derive(Debug, PartialEq)]
pub struct DisplayTextFragment<'a> {
pub content: &'a str,
pub style: DisplayTextStyle,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DisplayTextStyle {
Regular,
Emphasis,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayAnnotationPart {
Standalone,
LabelContinuation,
Consequitive,
MultilineStart,
MultilineEnd,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DisplayMark {
pub mark_type: DisplayMarkType,
pub annotation_type: DisplayAnnotationType,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayMarkType {
AnnotationThrough,
AnnotationStart,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayAnnotationType {
None,
Error,
Warning,
Info,
Note,
Help,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayHeaderType {
Initial,
Continuation,
}