@@ -253,27 +253,26 @@ impl RenderedLineKind {
253
253
254
254
impl StyledBuffer {
255
255
fn new ( ) -> StyledBuffer {
256
- StyledBuffer { text : Vec :: new ( ) , styles : Vec :: new ( ) }
256
+ StyledBuffer { text : vec ! [ ] , styles : vec ! [ ] }
257
257
}
258
258
259
259
fn render ( & self , source_kind : RenderedLineKind ) -> Vec < RenderedLine > {
260
- let mut output : Vec < RenderedLine > = Vec :: new ( ) ;
261
- let mut styled_vec : Vec < StyledString > = Vec :: new ( ) ;
260
+ let mut output: Vec < RenderedLine > = vec ! [ ] ;
261
+ let mut styled_vec: Vec < StyledString > = vec ! [ ] ;
262
262
263
-
264
- for ( row, row_style) in self . text . iter ( ) . zip ( self . styles . iter ( ) ) {
263
+ for ( row, row_style) in self . text . iter ( ) . zip ( & self . styles ) {
265
264
let mut current_style = NoStyle ;
266
265
let mut current_text = String :: new ( ) ;
267
266
268
- for ( c, s) in row. iter ( ) . zip ( row_style. iter ( ) ) {
269
- if * s != current_style {
267
+ for ( & c, & s) in row. iter ( ) . zip ( row_style) {
268
+ if s != current_style {
270
269
if !current_text. is_empty ( ) {
271
270
styled_vec. push ( StyledString { text : current_text, style : current_style } ) ;
272
271
}
273
- current_style = * s;
272
+ current_style = s;
274
273
current_text = String :: new ( ) ;
275
274
}
276
- current_text. push ( * c) ;
275
+ current_text. push ( c) ;
277
276
}
278
277
if !current_text. is_empty ( ) {
279
278
styled_vec. push ( StyledString { text : current_text, style : current_style } ) ;
@@ -285,23 +284,22 @@ impl StyledBuffer {
285
284
} else {
286
285
output. push ( RenderedLine { text : styled_vec, kind : Annotations } ) ;
287
286
}
288
- styled_vec = Vec :: new ( ) ;
287
+ styled_vec = vec ! [ ] ;
289
288
}
290
289
291
290
output
292
291
}
293
292
294
293
fn putc ( & mut self , line : usize , col : usize , chr : char , style : Style ) {
295
294
while line >= self . text . len ( ) {
296
- self . text . push ( Vec :: new ( ) ) ;
297
- self . styles . push ( Vec :: new ( ) ) ;
295
+ self . text . push ( vec ! [ ] ) ;
296
+ self . styles . push ( vec ! [ ] ) ;
298
297
}
299
298
300
299
if col < self . text [ line] . len ( ) {
301
300
self . text [ line] [ col] = chr;
302
301
self . styles [ line] [ col] = style;
303
- }
304
- else {
302
+ } else {
305
303
while self . text [ line] . len ( ) < col {
306
304
self . text [ line] . push ( ' ' ) ;
307
305
self . styles [ line] . push ( NoStyle ) ;
@@ -319,11 +317,16 @@ impl StyledBuffer {
319
317
}
320
318
}
321
319
320
+ fn set_style ( & mut self , line : usize , col : usize , style : Style ) {
321
+ if self . styles . len ( ) > line && self . styles [ line] . len ( ) > col {
322
+ self . styles [ line] [ col] = style;
323
+ }
324
+ }
325
+
322
326
fn append ( & mut self , line : usize , string : & str , style : Style ) {
323
327
if line >= self . text . len ( ) {
324
328
self . puts ( line, 0 , string, style) ;
325
- }
326
- else {
329
+ } else {
327
330
let col = self . text [ line] . len ( ) ;
328
331
self . puts ( line, col, string, style) ;
329
332
}
@@ -466,7 +469,7 @@ impl FileInfo {
466
469
text: lo. file. name. clone( ) ,
467
470
style: FileNameStyle ,
468
471
} , StyledString {
469
- text: format!( " ( {}:{}) " , lo. line, lo. col. 0 + 1 ) ,
472
+ text: format!( ": {}:{}" , lo. line, lo. col. 0 + 1 ) ,
470
473
style: LineAndColumn ,
471
474
} ] ,
472
475
kind : PrimaryFileName ,
@@ -507,12 +510,10 @@ impl FileInfo {
507
510
None => annotation. start_col == 0 &&
508
511
annotation. end_col == source_string. len ( )
509
512
}
510
- }
511
- else {
513
+ } else {
512
514
false
513
515
}
514
- }
515
- else {
516
+ } else {
516
517
false
517
518
} ;
518
519
@@ -531,12 +532,10 @@ impl FileInfo {
531
532
532
533
prev_ends_at_eol = annotation_ends_at_eol;
533
534
}
534
- }
535
- else {
535
+ } else {
536
536
if group. len ( ) > 1 {
537
537
output. push ( RenderedLine :: from ( ( String :: new ( ) , NoStyle , Elision ) ) ) ;
538
- }
539
- else {
538
+ } else {
540
539
let mut v: Vec < RenderedLine > =
541
540
group. iter ( ) . flat_map ( |line| self . render_line ( line) ) . collect ( ) ;
542
541
output. append ( & mut v) ;
@@ -596,8 +595,8 @@ impl FileInfo {
596
595
for p in annotation. start_col .. annotation. end_col {
597
596
if annotation. is_primary {
598
597
styled_buffer. putc ( 1 , p, '^' , UnderlinePrimary ) ;
599
- }
600
- else {
598
+ styled_buffer . set_style ( 0 , p , UnderlinePrimary ) ;
599
+ } else {
601
600
styled_buffer. putc ( 1 , p, '-' , UnderlineSecondary ) ;
602
601
}
603
602
}
0 commit comments