@@ -35,7 +35,8 @@ use crate::snippet;
3535use std:: cmp:: { max, min} ;
3636use std:: fmt:: { Display , Write } ;
3737use std:: { cmp, fmt} ;
38- use yansi_term:: Style ;
38+
39+ use anstyle:: Style ;
3940
4041use crate :: renderer:: StyleSheet ;
4142
@@ -204,7 +205,15 @@ impl<'a> DisplayList<'a> {
204205 for fragment in label {
205206 match fragment. style {
206207 DisplayTextStyle :: Regular => fragment. content . fmt ( f) ?,
207- DisplayTextStyle :: Emphasis => emphasis_style. paint ( fragment. content ) . fmt ( f) ?,
208+ DisplayTextStyle :: Emphasis => {
209+ write ! (
210+ f,
211+ "{}{}{}" ,
212+ emphasis_style. render( ) ,
213+ fragment. content,
214+ emphasis_style. render_reset( )
215+ ) ?;
216+ }
208217 }
209218 }
210219 Ok ( ( ) )
@@ -231,26 +240,21 @@ impl<'a> DisplayList<'a> {
231240 if formatted_len == 0 {
232241 self . format_label ( & annotation. label , f)
233242 } 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) ?;
243+ write ! ( f, "{}" , color. render( ) ) ?;
244+ Self :: format_annotation_type ( & annotation. annotation_type , f) ?;
245+ if let Some ( id) = & annotation. id {
246+ f. write_char ( '[' ) ?;
247+ f. write_str ( id) ?;
248+ f. write_char ( ']' ) ?;
249+ }
250+ write ! ( f, "{}" , color. render_reset( ) ) ?;
245251
246252 if !is_annotation_empty ( annotation) {
247253 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) ?;
254+ write ! ( f, "{}" , color. render( ) ) ?;
255+ f. write_str ( ": " ) ?;
256+ self . format_label ( & annotation. label , f) ?;
257+ write ! ( f, "{}" , color. render_reset( ) ) ?;
254258 } else {
255259 f. write_str ( ": " ) ?;
256260 self . format_label ( & annotation. label , f) ?;
@@ -361,25 +365,21 @@ impl<'a> DisplayList<'a> {
361365 _ => range. 0 ,
362366 } ;
363367
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) ?;
368+ write ! ( f, "{}" , color. render( ) ) ?;
369+ format_repeat_char ( indent_char, indent_length + 1 , f) ?;
370+ format_repeat_char ( mark, range. 1 - indent_length, f) ?;
371+ write ! ( f, "{}" , color. render_reset( ) ) ?;
370372
371373 if !is_annotation_empty ( annotation) {
372374 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) ?;
375+ write ! ( f, "{}" , color. render( ) ) ?;
376+ self . format_annotation (
377+ annotation,
378+ annotation_part == & DisplayAnnotationPart :: LabelContinuation ,
379+ true ,
380+ f,
381+ ) ?;
382+ write ! ( f, "{}" , color. render_reset( ) ) ?;
383383 }
384384
385385 Ok ( ( ) )
@@ -408,7 +408,13 @@ impl<'a> DisplayList<'a> {
408408
409409 if let Some ( ( col, row) ) = pos {
410410 format_repeat_char ( ' ' , lineno_width, f) ?;
411- lineno_color. paint ( header_sigil) . fmt ( f) ?;
411+ write ! (
412+ f,
413+ "{}{}{}" ,
414+ lineno_color. render( ) ,
415+ header_sigil,
416+ lineno_color. render_reset( )
417+ ) ?;
412418 f. write_char ( ' ' ) ?;
413419 path. fmt ( f) ?;
414420 f. write_char ( ':' ) ?;
@@ -417,7 +423,13 @@ impl<'a> DisplayList<'a> {
417423 row. fmt ( f)
418424 } else {
419425 format_repeat_char ( ' ' , lineno_width, f) ?;
420- lineno_color. paint ( header_sigil) . fmt ( f) ?;
426+ write ! (
427+ f,
428+ "{}{}{}" ,
429+ lineno_color. render( ) ,
430+ header_sigil,
431+ lineno_color. render_reset( )
432+ ) ?;
421433 f. write_char ( ' ' ) ?;
422434 path. fmt ( f)
423435 }
@@ -434,7 +446,12 @@ impl<'a> DisplayList<'a> {
434446 let lineno_color = self . stylesheet . line_no ( ) ;
435447 format_repeat_char ( ' ' , lineno_width, f) ?;
436448 f. write_char ( ' ' ) ?;
437- lineno_color. paint ( "=" ) . fmt ( f) ?;
449+ write ! (
450+ f,
451+ "{}={}" ,
452+ lineno_color. render( ) ,
453+ lineno_color. render_reset( )
454+ ) ?;
438455 f. write_char ( ' ' ) ?;
439456 }
440457 }
@@ -459,22 +476,18 @@ impl<'a> DisplayList<'a> {
459476 } => {
460477 let lineno_color = self . stylesheet . line_no ( ) ;
461478 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) ?;
479+ write ! ( f, "{}" , lineno_color. render( ) ) ?;
480+ f. write_str ( Self :: ANONYMIZED_LINE_NUM ) ?;
481+ f. write_str ( " |" ) ?;
482+ write ! ( f, "{}" , lineno_color. render_reset( ) ) ?;
468483 } 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) ?;
484+ write ! ( f, "{}" , lineno_color. render( ) ) ?;
485+ match lineno {
486+ Some ( n) => write ! ( f, "{:>width$}" , n, width = lineno_width) ,
487+ None => format_repeat_char ( ' ' , lineno_width, f) ,
488+ } ?;
489+ f. write_str ( " |" ) ?;
490+ write ! ( f, "{}" , lineno_color. render_reset( ) ) ?;
478491 }
479492 if * line != DisplaySourceLine :: Empty {
480493 if !inline_marks. is_empty ( ) || 0 < inline_marks_width {
@@ -508,14 +521,13 @@ impl<'a> DisplayList<'a> {
508521 ) -> fmt:: Result {
509522 format_repeat_char ( ' ' , inline_marks_width - inline_marks. len ( ) , f) ?;
510523 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) ?;
524+ let annotation_style = self . get_annotation_style ( & mark. annotation_type ) ;
525+ write ! ( f, "{}" , annotation_style. render( ) ) ?;
526+ f. write_char ( match mark. mark_type {
527+ DisplayMarkType :: AnnotationThrough => '|' ,
528+ DisplayMarkType :: AnnotationStart => '/' ,
529+ } ) ?;
530+ write ! ( f, "{}" , annotation_style. render_reset( ) ) ?;
519531 }
520532 Ok ( ( ) )
521533 }
0 commit comments