Skip to content

Commit 25d519a

Browse files
committed
refactor(render): Pull out Message formatting
1 parent 20842e5 commit 25d519a

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/renderer/display_list.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -106,33 +106,12 @@ impl<'a> DisplayList<'a> {
106106
const WARNING_TXT: &'static str = "warning";
107107

108108
pub(crate) fn new(
109-
snippet::Message {
110-
level,
111-
id,
112-
title,
113-
footer,
114-
snippets,
115-
}: snippet::Message<'a>,
109+
message: snippet::Message<'a>,
116110
stylesheet: &'a Stylesheet,
117111
anonymized_line_numbers: bool,
118112
margin: Option<Margin>,
119113
) -> DisplayList<'a> {
120-
let mut body = vec![];
121-
122-
body.push(format_title(level, id, title));
123-
124-
for (idx, snippet) in snippets.into_iter().enumerate() {
125-
body.append(&mut format_snippet(
126-
snippet,
127-
idx == 0,
128-
!footer.is_empty(),
129-
margin,
130-
));
131-
}
132-
133-
for annotation in footer {
134-
body.append(&mut format_footer(annotation));
135-
}
114+
let body = format_message(message, margin);
136115

137116
Self {
138117
body,
@@ -719,6 +698,36 @@ impl<'a> Iterator for CursorLines<'a> {
719698
}
720699
}
721700

701+
fn format_message<'a>(
702+
snippet::Message {
703+
level,
704+
id,
705+
title,
706+
footer,
707+
snippets,
708+
}: snippet::Message<'a>,
709+
margin: Option<Margin>,
710+
) -> Vec<DisplayLine<'a>> {
711+
let mut body = vec![];
712+
713+
body.push(format_title(level, id, title));
714+
715+
for (idx, snippet) in snippets.into_iter().enumerate() {
716+
body.append(&mut format_snippet(
717+
snippet,
718+
idx == 0,
719+
!footer.is_empty(),
720+
margin,
721+
));
722+
}
723+
724+
for annotation in footer {
725+
body.append(&mut format_footer(annotation));
726+
}
727+
728+
body
729+
}
730+
722731
fn format_title<'a>(level: crate::Level, id: Option<&'a str>, label: &'a str) -> DisplayLine<'a> {
723732
DisplayLine::Raw(DisplayRawLine::Annotation {
724733
annotation: Annotation {

0 commit comments

Comments
 (0)