@@ -35,9 +35,8 @@ use crate::snippet;
3535use std:: cmp:: { max, min} ;
3636use std:: fmt:: { Display , Write } ;
3737use std:: { cmp, fmt} ;
38- use yansi_term:: Style ;
3938
40- use crate :: renderer:: stylesheet:: Stylesheet ;
39+ use crate :: renderer:: { stylesheet:: Stylesheet , Style } ;
4140
4241/// List of lines to be displayed.
4342pub struct DisplayList < ' a > {
@@ -204,7 +203,15 @@ impl<'a> DisplayList<'a> {
204203 for fragment in label {
205204 match fragment. style {
206205 DisplayTextStyle :: Regular => fragment. content . fmt ( f) ?,
207- DisplayTextStyle :: Emphasis => emphasis_style. paint ( fragment. content ) . fmt ( f) ?,
206+ DisplayTextStyle :: Emphasis => {
207+ write ! (
208+ f,
209+ "{}{}{}" ,
210+ emphasis_style. render( ) ,
211+ fragment. content,
212+ emphasis_style. render_reset( )
213+ ) ?;
214+ }
208215 }
209216 }
210217 Ok ( ( ) )
@@ -231,26 +238,21 @@ impl<'a> DisplayList<'a> {
231238 if formatted_len == 0 {
232239 self . format_label ( & annotation. label , f)
233240 } else {
234- color
235- . paint_fn ( Box :: new ( |f : & mut fmt:: Formatter < ' _ > | {
236- Self :: format_annotation_type ( & annotation. annotation_type , f) ?;
237- if let Some ( id) = & annotation. id {
238- f. write_char ( '[' ) ?;
239- f. write_str ( id) ?;
240- f. write_char ( ']' ) ?;
241- }
242- Ok ( ( ) )
243- } ) )
244- . fmt ( f) ?;
241+ write ! ( f, "{}" , color. render( ) ) ?;
242+ Self :: format_annotation_type ( & annotation. annotation_type , f) ?;
243+ if let Some ( id) = & annotation. id {
244+ f. write_char ( '[' ) ?;
245+ f. write_str ( id) ?;
246+ f. write_char ( ']' ) ?;
247+ }
248+ write ! ( f, "{}" , color. render_reset( ) ) ?;
245249
246250 if !is_annotation_empty ( annotation) {
247251 if in_source {
248- color
249- . paint_fn ( Box :: new ( |f : & mut fmt:: Formatter < ' _ > | {
250- f. write_str ( ": " ) ?;
251- self . format_label ( & annotation. label , f)
252- } ) )
253- . fmt ( f) ?;
252+ write ! ( f, "{}" , color. render( ) ) ?;
253+ f. write_str ( ": " ) ?;
254+ self . format_label ( & annotation. label , f) ?;
255+ write ! ( f, "{}" , color. render_reset( ) ) ?;
254256 } else {
255257 f. write_str ( ": " ) ?;
256258 self . format_label ( & annotation. label , f) ?;
@@ -361,25 +363,21 @@ impl<'a> DisplayList<'a> {
361363 _ => range. 0 ,
362364 } ;
363365
364- color
365- . paint_fn ( |f| {
366- format_repeat_char ( indent_char, indent_length + 1 , f) ?;
367- format_repeat_char ( mark, range. 1 - indent_length, f)
368- } )
369- . fmt ( f) ?;
366+ write ! ( f, "{}" , color. render( ) ) ?;
367+ format_repeat_char ( indent_char, indent_length + 1 , f) ?;
368+ format_repeat_char ( mark, range. 1 - indent_length, f) ?;
369+ write ! ( f, "{}" , color. render_reset( ) ) ?;
370370
371371 if !is_annotation_empty ( annotation) {
372372 f. write_char ( ' ' ) ?;
373- color
374- . paint_fn ( |f| {
375- self . format_annotation (
376- annotation,
377- annotation_part == & DisplayAnnotationPart :: LabelContinuation ,
378- true ,
379- f,
380- )
381- } )
382- . fmt ( f) ?;
373+ write ! ( f, "{}" , color. render( ) ) ?;
374+ self . format_annotation (
375+ annotation,
376+ annotation_part == & DisplayAnnotationPart :: LabelContinuation ,
377+ true ,
378+ f,
379+ ) ?;
380+ write ! ( f, "{}" , color. render_reset( ) ) ?;
383381 }
384382
385383 Ok ( ( ) )
@@ -408,7 +406,13 @@ impl<'a> DisplayList<'a> {
408406
409407 if let Some ( ( col, row) ) = pos {
410408 format_repeat_char ( ' ' , lineno_width, f) ?;
411- lineno_color. paint ( header_sigil) . fmt ( f) ?;
409+ write ! (
410+ f,
411+ "{}{}{}" ,
412+ lineno_color. render( ) ,
413+ header_sigil,
414+ lineno_color. render_reset( )
415+ ) ?;
412416 f. write_char ( ' ' ) ?;
413417 path. fmt ( f) ?;
414418 f. write_char ( ':' ) ?;
@@ -417,7 +421,13 @@ impl<'a> DisplayList<'a> {
417421 row. fmt ( f)
418422 } else {
419423 format_repeat_char ( ' ' , lineno_width, f) ?;
420- lineno_color. paint ( header_sigil) . fmt ( f) ?;
424+ write ! (
425+ f,
426+ "{}{}{}" ,
427+ lineno_color. render( ) ,
428+ header_sigil,
429+ lineno_color. render_reset( )
430+ ) ?;
421431 f. write_char ( ' ' ) ?;
422432 path. fmt ( f)
423433 }
@@ -434,7 +444,12 @@ impl<'a> DisplayList<'a> {
434444 let lineno_color = self . stylesheet . line_no ( ) ;
435445 format_repeat_char ( ' ' , lineno_width, f) ?;
436446 f. write_char ( ' ' ) ?;
437- lineno_color. paint ( "=" ) . fmt ( f) ?;
447+ write ! (
448+ f,
449+ "{}={}" ,
450+ lineno_color. render( ) ,
451+ lineno_color. render_reset( )
452+ ) ?;
438453 f. write_char ( ' ' ) ?;
439454 }
440455 }
@@ -459,22 +474,18 @@ impl<'a> DisplayList<'a> {
459474 } => {
460475 let lineno_color = self . stylesheet . line_no ( ) ;
461476 if self . anonymized_line_numbers && lineno. is_some ( ) {
462- lineno_color
463- . paint_fn ( Box :: new ( |f : & mut fmt:: Formatter < ' _ > | {
464- f. write_str ( Self :: ANONYMIZED_LINE_NUM ) ?;
465- f. write_str ( " |" )
466- } ) )
467- . fmt ( f) ?;
477+ write ! ( f, "{}" , lineno_color. render( ) ) ?;
478+ f. write_str ( Self :: ANONYMIZED_LINE_NUM ) ?;
479+ f. write_str ( " |" ) ?;
480+ write ! ( f, "{}" , lineno_color. render_reset( ) ) ?;
468481 } else {
469- lineno_color
470- . paint_fn ( Box :: new ( |f : & mut fmt:: Formatter < ' _ > | {
471- match lineno {
472- Some ( n) => write ! ( f, "{:>width$}" , n, width = lineno_width) ,
473- None => format_repeat_char ( ' ' , lineno_width, f) ,
474- } ?;
475- f. write_str ( " |" )
476- } ) )
477- . fmt ( f) ?;
482+ write ! ( f, "{}" , lineno_color. render( ) ) ?;
483+ match lineno {
484+ Some ( n) => write ! ( f, "{:>width$}" , n, width = lineno_width) ,
485+ None => format_repeat_char ( ' ' , lineno_width, f) ,
486+ } ?;
487+ f. write_str ( " |" ) ?;
488+ write ! ( f, "{}" , lineno_color. render_reset( ) ) ?;
478489 }
479490 if * line != DisplaySourceLine :: Empty {
480491 if !inline_marks. is_empty ( ) || 0 < inline_marks_width {
@@ -508,14 +519,13 @@ impl<'a> DisplayList<'a> {
508519 ) -> fmt:: Result {
509520 format_repeat_char ( ' ' , inline_marks_width - inline_marks. len ( ) , f) ?;
510521 for mark in inline_marks {
511- self . get_annotation_style ( & mark. annotation_type )
512- . paint_fn ( Box :: new ( |f : & mut fmt:: Formatter < ' _ > | {
513- f. write_char ( match mark. mark_type {
514- DisplayMarkType :: AnnotationThrough => '|' ,
515- DisplayMarkType :: AnnotationStart => '/' ,
516- } )
517- } ) )
518- . fmt ( f) ?;
522+ let annotation_style = self . get_annotation_style ( & mark. annotation_type ) ;
523+ write ! ( f, "{}" , annotation_style. render( ) ) ?;
524+ f. write_char ( match mark. mark_type {
525+ DisplayMarkType :: AnnotationThrough => '|' ,
526+ DisplayMarkType :: AnnotationStart => '/' ,
527+ } ) ?;
528+ write ! ( f, "{}" , annotation_style. render_reset( ) ) ?;
519529 }
520530 Ok ( ( ) )
521531 }
0 commit comments