Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite7179c3

Browse files
author
Zibi Braniecki
committed
Annotate the type of DisplayMark
1 parent4d70e53 commite7179c3

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

‎src/display_list.rs‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ pub enum DisplayAnnotationPart {
5656
}
5757

5858
#[derive(Debug,Clone,PartialEq)]
59-
pubenumDisplayMark{
59+
pubstructDisplayMark{
60+
pubmark_type:DisplayMarkType,
61+
pubannotation_type:DisplayAnnotationType,
62+
}
63+
64+
#[derive(Debug,Clone,PartialEq)]
65+
pubenumDisplayMarkType{
6066
AnnotationThrough,
6167
AnnotationStart,
6268
}
@@ -285,7 +291,12 @@ fn format_body(slice: &Slice, has_footer: bool) -> Vec<DisplayLine> {
285291
..
286292
} = body[body_idx]
287293
{
288-
inline_marks.push(DisplayMark::AnnotationStart);
294+
inline_marks.push(DisplayMark{
295+
mark_type:DisplayMarkType::AnnotationStart,
296+
annotation_type:DisplayAnnotationType::from(
297+
annotation.annotation_type,
298+
),
299+
});
289300
}
290301
}else{
291302
let range =(start - line_start, start - line_start +1);
@@ -311,7 +322,12 @@ fn format_body(slice: &Slice, has_footer: bool) -> Vec<DisplayLine> {
311322
..
312323
} = body[body_idx]
313324
{
314-
inline_marks.push(DisplayMark::AnnotationThrough);
325+
inline_marks.push(DisplayMark{
326+
mark_type:DisplayMarkType::AnnotationThrough,
327+
annotation_type:DisplayAnnotationType::from(
328+
annotation.annotation_type,
329+
),
330+
});
315331
}
316332
false
317333
}
@@ -321,13 +337,23 @@ fn format_body(slice: &Slice, has_footer: bool) -> Vec<DisplayLine> {
321337
..
322338
} = body[body_idx]
323339
{
324-
inline_marks.push(DisplayMark::AnnotationThrough);
340+
inline_marks.push(DisplayMark{
341+
mark_type:DisplayMarkType::AnnotationThrough,
342+
annotation_type:DisplayAnnotationType::from(
343+
annotation.annotation_type,
344+
),
345+
});
325346
}
326347
let range =(end - line_start, end - line_start +1);
327348
body.insert(
328349
body_idx +1,
329350
DisplayLine::SourceAnnotation{
330-
inline_marks:vec![DisplayMark::AnnotationThrough],
351+
inline_marks:vec![DisplayMark{
352+
mark_type:DisplayMarkType::AnnotationThrough,
353+
annotation_type:DisplayAnnotationType::from(
354+
annotation.annotation_type,
355+
),
356+
}],
331357
range,
332358
label:format_label(Some(&annotation.label),None),
333359
annotation_type:DisplayAnnotationType::from(

‎src/format.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use display_list::{DisplayAnnotationPart,DisplayAnnotationType,DisplayHeaderType,DisplayLine,
2-
DisplayList,DisplayMark,DisplayTextFragment};
2+
DisplayList,DisplayMark,DisplayMarkType,DisplayTextFragment};
33
use display_list_formatting::DisplayListFormatting;
44
use std::fmt;
55

@@ -21,9 +21,12 @@ impl DisplayListFormatting for Formatter {
2121
"{:>width$}",
2222
inline_marks
2323
.iter()
24-
.map(|mark|match mark{
25-
DisplayMark::AnnotationThrough =>"|",
26-
DisplayMark::AnnotationStart =>"/",
24+
.map(|mark|{
25+
let sigil =match mark.mark_type{
26+
DisplayMarkType::AnnotationThrough =>"|",
27+
DisplayMarkType::AnnotationStart =>"/",
28+
};
29+
sigil
2730
})
2831
.collect::<Vec<&str>>()
2932
.join(""),

‎src/format_color.rs‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ extern crate ansi_term;
33
useself::ansi_term::Color::Fixed;
44
useself::ansi_term::Style;
55
use display_list::{DisplayAnnotationPart,DisplayAnnotationType,DisplayHeaderType,DisplayLine,
6-
DisplayList,DisplayMark,DisplayTextFragment,DisplayTextStyle};
6+
DisplayList,DisplayMark,DisplayMarkType,DisplayTextFragment,
7+
DisplayTextStyle};
78
use display_list_formatting::DisplayListFormatting;
89
use std::fmt;
910

@@ -25,11 +26,21 @@ impl DisplayListFormatting for Formatter {
2526
"{:>width$}",
2627
inline_marks
2728
.iter()
28-
.map(|mark|match mark{
29-
DisplayMark::AnnotationThrough =>"|",
30-
DisplayMark::AnnotationStart =>"/",
29+
.map(|mark|{
30+
let sigil =match mark.mark_type{
31+
DisplayMarkType::AnnotationThrough =>"|",
32+
DisplayMarkType::AnnotationStart =>"/",
33+
};
34+
let color =match mark.annotation_type{
35+
DisplayAnnotationType::Error =>Fixed(9).bold(),
36+
DisplayAnnotationType::Warning =>Fixed(11).bold(),
37+
DisplayAnnotationType::Info =>Fixed(12).bold(),
38+
DisplayAnnotationType::Note =>Style::new().bold(),
39+
DisplayAnnotationType::Help =>Fixed(14).bold(),
40+
};
41+
format!("{}", color.paint(sigil))
3142
})
32-
.collect::<Vec<&str>>()
43+
.collect::<Vec<String>>()
3344
.join(""),
3445
width = inline_marks_width
3546
)
@@ -63,20 +74,24 @@ impl DisplayListFormatting for Formatter {
6374
DisplayAnnotationType::Note =>Style::new().bold(),
6475
DisplayAnnotationType::Help =>Fixed(14).bold(),
6576
};
77+
let indent =if indent_char ==" "{
78+
indent_char.repeat(range.0)
79+
}else{
80+
format!("{}", color.paint(indent_char.repeat(range.0)))
81+
};
6682
ifletSome((first, rest)) =Self::format_label(label)
6783
.lines()
6884
.collect::<Vec<&str>>()
6985
.split_first()
7086
{
71-
let indent = range.1;
7287
writeln!(
7388
f,
7489
"{}{}{}{} {}",
7590
Fixed(12)
7691
.bold()
7792
.paint(format!("{} |"," ".repeat(lineno_width))),
7893
inline_marks,
79-
indent_char.repeat(range.0),
94+
indent,
8095
color.paint(mark.repeat(range.1 - range.0)),
8196
color.paint(*first),
8297
)?;
@@ -88,7 +103,7 @@ impl DisplayListFormatting for Formatter {
88103
.bold()
89104
.paint(format!("{} |"," ".repeat(lineno_width))),
90105
inline_marks,
91-
" ".repeat(indent),
106+
" ".repeat(range.1),
92107
color.paint(*line),
93108
)?;
94109
}
@@ -100,7 +115,7 @@ impl DisplayListFormatting for Formatter {
100115
.bold()
101116
.paint(format!("{} |"," ".repeat(lineno_width))),
102117
inline_marks,
103-
indent_char.repeat(range.0),
118+
indent,
104119
color.paint(mark.repeat(range.1 - range.0)),
105120
)?;
106121
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp