|
1 |
| -#[cfg(feature = "ansi_term")] |
2 |
| -use annotate_snippets::renderers::ascii_default::styles::color::Style as ColorStyle; |
3 |
| -#[cfg(feature = "termcolor")] |
4 |
| -use annotate_snippets::renderers::ascii_default::styles::color2::Style as ColorStyle; |
5 |
| -#[cfg(all(not(feature = "ansi_term"), not(feature = "termcolor")))] |
6 |
| -use annotate_snippets::renderers::ascii_default::styles::plain::Style as PlainStyle; |
7 |
| -use annotate_snippets::renderers::ascii_default::Renderer as AsciiRenderer; |
8 | 1 | use annotate_snippets::DisplayList;
|
9 | 2 | use annotate_snippets::{Annotation, AnnotationType, SourceAnnotation};
|
10 | 3 | use annotate_snippets::{Slice, Snippet};
|
11 | 4 |
|
| 5 | +use annotate_snippets::renderers::ascii_default::get_renderer; |
| 6 | +use annotate_snippets::renderers::Renderer; |
| 7 | + |
12 | 8 | fn main() {
|
13 | 9 | let source = r#") -> Option<String> {
|
14 | 10 | for ann in annotations {
|
@@ -48,24 +44,19 @@ fn main() {
|
48 | 44 | SourceAnnotation {
|
49 | 45 | label: "expected `Option<String>` because of return type",
|
50 | 46 | annotation_type: AnnotationType::Warning,
|
51 |
| - range: (5, 19), |
| 47 | + range: 5..19, |
52 | 48 | },
|
53 | 49 | SourceAnnotation {
|
54 | 50 | label: "expected enum `std::option::Option`",
|
55 | 51 | annotation_type: AnnotationType::Error,
|
56 |
| - range: (23, 725), |
| 52 | + range: 23..725, |
57 | 53 | },
|
58 | 54 | ],
|
59 | 55 | }],
|
60 | 56 | };
|
61 | 57 | let dl = DisplayList::from(&snippet);
|
| 58 | + let r = get_renderer(); |
62 | 59 |
|
63 |
| - #[cfg(all(not(feature = "ansi_term"), not(feature = "termcolor")))] |
64 |
| - let r = AsciiRenderer::<PlainStyle>::new(); |
65 |
| - #[cfg(feature = "ansi_term")] |
66 |
| - let r = AsciiRenderer::<ColorStyle>::new(); |
67 |
| - #[cfg(feature = "termcolor")] |
68 |
| - let r = AsciiRenderer::<ColorStyle>::new(); |
69 | 60 | let mut s: Vec<u8> = Vec::new();
|
70 | 61 | r.fmt(&mut s, &dl).unwrap();
|
71 | 62 | println!("{}", std::str::from_utf8(&s).unwrap());
|
|
0 commit comments