Skip to content

Commit 48cd91b

Browse files
author
Zibi Braniecki
committed
Update color support
1 parent 6c5002a commit 48cd91b

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

examples/multislice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate annotate_snippets;
22

33
use annotate_snippets::display_list::DisplayList;
4-
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, TitleAnnotation};
4+
use annotate_snippets::snippet::{AnnotationType, Slice, Snippet, TitleAnnotation};
55

66
fn main() {
77
let snippet = Snippet {

src/format_color.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate ansi_term;
33
use self::ansi_term::Color::Fixed;
44
use self::ansi_term::Style;
55
use display_list::{DisplayAnnotationType, DisplayLine, DisplayList, DisplayMark,
6-
DisplaySnippetType};
6+
DisplaySnippetType, DisplayHeaderType};
77
use display_list_formatting::DisplayListFormatting;
88
use std::fmt;
99

@@ -109,15 +109,29 @@ impl DisplayListFormatting for Formatter {
109109
Style::new().bold().paint(format!(": {}", label))
110110
)
111111
}
112-
DisplayLine::Origin { path, row, col } => writeln!(
113-
f,
114-
"{}{} {}:{}:{}",
115-
" ".repeat(lineno_width),
116-
Fixed(12).bold().paint("-->"),
112+
DisplayLine::Origin {
117113
path,
118-
row,
119-
col
120-
),
114+
pos,
115+
header_type,
116+
} => {
117+
let header_sigil = match header_type {
118+
DisplayHeaderType::Initial => "-->",
119+
DisplayHeaderType::Continuation => ":::",
120+
};
121+
if let Some((row, col)) = pos {
122+
writeln!(
123+
f,
124+
"{}{} {}:{}:{}",
125+
" ".repeat(lineno_width),
126+
Fixed(12).bold().paint(header_sigil),
127+
path,
128+
row,
129+
col
130+
)
131+
} else {
132+
writeln!(f, "{}{} {}", " ".repeat(lineno_width), Fixed(12).bold().paint(header_sigil), path,)
133+
}
134+
}
121135
DisplayLine::EmptySource => {
122136
let prefix = format!("{} |", " ".repeat(lineno_width));
123137
writeln!(f, "{}", Fixed(12).bold().paint(prefix))

0 commit comments

Comments
 (0)