@@ -3,7 +3,8 @@ extern crate ansi_term;
3
3
use self :: ansi_term:: Color :: Fixed ;
4
4
use self :: ansi_term:: Style ;
5
5
use display_list:: { DisplayAnnotationPart , DisplayAnnotationType , DisplayHeaderType , DisplayLine ,
6
- DisplayList , DisplayMark , DisplayTextFragment , DisplayTextStyle } ;
6
+ DisplayList , DisplayMark , DisplayMarkType , DisplayTextFragment ,
7
+ DisplayTextStyle } ;
7
8
use display_list_formatting:: DisplayListFormatting ;
8
9
use std:: fmt;
9
10
@@ -25,11 +26,21 @@ impl DisplayListFormatting for Formatter {
25
26
"{:>width$}" ,
26
27
inline_marks
27
28
. 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) )
31
42
} )
32
- . collect:: <Vec <& str >>( )
43
+ . collect:: <Vec <String >>( )
33
44
. join( "" ) ,
34
45
width = inline_marks_width
35
46
)
@@ -63,20 +74,24 @@ impl DisplayListFormatting for Formatter {
63
74
DisplayAnnotationType :: Note => Style :: new ( ) . bold ( ) ,
64
75
DisplayAnnotationType :: Help => Fixed ( 14 ) . bold ( ) ,
65
76
} ;
77
+ let indent = if indent_char == " " {
78
+ indent_char. repeat ( range. 0 )
79
+ } else {
80
+ format ! ( "{}" , color. paint( indent_char. repeat( range. 0 ) ) )
81
+ } ;
66
82
if let Some ( ( first, rest) ) = Self :: format_label ( label)
67
83
. lines ( )
68
84
. collect :: < Vec < & str > > ( )
69
85
. split_first ( )
70
86
{
71
- let indent = range. 1 ;
72
87
writeln ! (
73
88
f,
74
89
"{}{}{}{} {}" ,
75
90
Fixed ( 12 )
76
91
. bold( )
77
92
. paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
78
93
inline_marks,
79
- indent_char . repeat ( range . 0 ) ,
94
+ indent ,
80
95
color. paint( mark. repeat( range. 1 - range. 0 ) ) ,
81
96
color. paint( * first) ,
82
97
) ?;
@@ -88,7 +103,7 @@ impl DisplayListFormatting for Formatter {
88
103
. bold( )
89
104
. paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
90
105
inline_marks,
91
- " " . repeat( indent ) ,
106
+ " " . repeat( range . 1 ) ,
92
107
color. paint( * line) ,
93
108
) ?;
94
109
}
@@ -100,7 +115,7 @@ impl DisplayListFormatting for Formatter {
100
115
. bold( )
101
116
. paint( format!( "{} |" , " " . repeat( lineno_width) ) ) ,
102
117
inline_marks,
103
- indent_char . repeat ( range . 0 ) ,
118
+ indent ,
104
119
color. paint( mark. repeat( range. 1 - range. 0 ) ) ,
105
120
) ?;
106
121
}
0 commit comments