Skip to content

Commit b08c58e

Browse files
committed
Fix example
1 parent ab0a303 commit b08c58e

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

benches/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ fn create_snippet() {
5050
SourceAnnotation {
5151
label: "expected `Option<String>` because of return type",
5252
annotation_type: AnnotationType::Warning,
53-
range: (5, 19),
53+
range: 5..19,
5454
},
5555
SourceAnnotation {
5656
label: "expected enum `std::option::Option`",
5757
annotation_type: AnnotationType::Error,
58-
range: (23, 725),
58+
range: 23..725,
5959
},
6060
],
6161
}],

examples/format.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
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;
81
use annotate_snippets::DisplayList;
92
use annotate_snippets::{Annotation, AnnotationType, SourceAnnotation};
103
use annotate_snippets::{Slice, Snippet};
114

5+
use annotate_snippets::renderers::ascii_default::get_renderer;
6+
use annotate_snippets::renderers::Renderer;
7+
128
fn main() {
139
let source = r#") -> Option<String> {
1410
for ann in annotations {
@@ -48,24 +44,19 @@ fn main() {
4844
SourceAnnotation {
4945
label: "expected `Option<String>` because of return type",
5046
annotation_type: AnnotationType::Warning,
51-
range: (5, 19),
47+
range: 5..19,
5248
},
5349
SourceAnnotation {
5450
label: "expected enum `std::option::Option`",
5551
annotation_type: AnnotationType::Error,
56-
range: (23, 725),
52+
range: 23..725,
5753
},
5854
],
5955
}],
6056
};
6157
let dl = DisplayList::from(&snippet);
58+
let r = get_renderer();
6259

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();
6960
let mut s: Vec<u8> = Vec::new();
7061
r.fmt(&mut s, &dl).unwrap();
7162
println!("{}", std::str::from_utf8(&s).unwrap());

src/renderers/ascii_default/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<S: StyleTrait> Renderer<S> {
8080
inline_marks,
8181
line,
8282
} => {
83-
let style = &[StyleType::LineNo];
83+
let style = &[StyleType::LineNo, StyleType::Emphasis];
8484
if let Some(lineno) = lineno {
8585
S::fmt(
8686
w,
@@ -121,7 +121,7 @@ impl<S: StyleTrait> Renderer<S> {
121121
let (_, style) = self.get_annotation_type_style(&annotation.annotation_type);
122122
let styles = [StyleType::Emphasis, style];
123123
let indent = if range.start == 0 { 0 } else { range.start + 1 };
124-
write!(w, "{:>1$}", "", indent)?;
124+
write!(w, "{:>width$}", "", width = indent)?;
125125
if range.start == 0 {
126126
S::fmt(
127127
w,
@@ -153,7 +153,7 @@ impl<S: StyleTrait> Renderer<S> {
153153
) -> std::io::Result<()> {
154154
match line {
155155
DisplayRawLine::Origin { path, pos } => {
156-
write!(w, "{:>1$}", "", lineno_max)?;
156+
write!(w, "{:>width$}", "", width = lineno_max)?;
157157
S::fmt(w, "-->", &[StyleType::Emphasis, StyleType::LineNo])?;
158158
write!(w, " {}", path)?;
159159
if let Some(line) = pos.0 {

0 commit comments

Comments
 (0)