@@ -3,7 +3,8 @@ extern crate ansi_term;
33use self :: ansi_term:: Color :: Fixed ;
44use self :: ansi_term:: Style ;
55use display_list:: { DisplayAnnotationPart , DisplayAnnotationType , DisplayHeaderType , DisplayLine ,
6- DisplayList , DisplayMark , DisplayTextFragment , DisplayTextStyle } ;
6+ DisplayList , DisplayMark , DisplayMarkType , DisplayTextFragment ,
7+ DisplayTextStyle } ;
78use display_list_formatting:: DisplayListFormatting ;
89use 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 if let Some ( ( 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