@@ -61,12 +61,15 @@ impl HumanReadableErrorType {
6161 }
6262 pub fn new_emitter (
6363 self ,
64- dst : Box < dyn Write + Send > ,
64+ mut dst : Box < dyn WriteColor + Send > ,
6565 fallback_bundle : LazyFallbackBundle ,
6666 ) -> EmitterWriter {
6767 let ( short, color_config) = self . unzip ( ) ;
6868 let color = color_config. suggests_using_colors ( ) ;
69- EmitterWriter :: new ( dst, fallback_bundle, color) . short_message ( short)
69+ if !dst. supports_color ( ) && color {
70+ dst = Box :: new ( Ansi :: new ( dst) ) ;
71+ }
72+ EmitterWriter :: new ( dst, fallback_bundle) . short_message ( short)
7073 }
7174}
7275
@@ -669,11 +672,10 @@ impl EmitterWriter {
669672 }
670673
671674 pub fn new (
672- dst : Box < dyn Write + Send > ,
675+ dst : Box < dyn WriteColor + Send > ,
673676 fallback_bundle : LazyFallbackBundle ,
674- colored : bool ,
675677 ) -> EmitterWriter {
676- Self :: create ( Raw ( dst, colored ) , fallback_bundle)
678+ Self :: create ( Raw ( dst) , fallback_bundle)
677679 }
678680
679681 fn maybe_anonymized ( & self , line_num : usize ) -> Cow < ' static , str > {
@@ -2603,15 +2605,13 @@ fn emit_to_destination(
26032605pub enum Destination {
26042606 Terminal ( StandardStream ) ,
26052607 Buffered ( BufferWriter ) ,
2606- // The bool denotes whether we should be emitting ansi color codes or not
2607- Raw ( Box < ( dyn Write + Send ) > , bool ) ,
2608+ Raw ( Box < ( dyn WriteColor + Send ) > ) ,
26082609}
26092610
26102611pub enum WritableDst < ' a > {
26112612 Terminal ( & ' a mut StandardStream ) ,
26122613 Buffered ( & ' a mut BufferWriter , Buffer ) ,
2613- Raw ( & ' a mut ( dyn Write + Send ) ) ,
2614- ColoredRaw ( Ansi < & ' a mut ( dyn Write + Send ) > ) ,
2614+ Raw ( & ' a mut ( dyn WriteColor + Send ) ) ,
26152615}
26162616
26172617impl Destination {
@@ -2637,16 +2637,15 @@ impl Destination {
26372637 let buf = t. buffer ( ) ;
26382638 WritableDst :: Buffered ( t, buf)
26392639 }
2640- Destination :: Raw ( ref mut t, false ) => WritableDst :: Raw ( t) ,
2641- Destination :: Raw ( ref mut t, true ) => WritableDst :: ColoredRaw ( Ansi :: new ( t) ) ,
2640+ Destination :: Raw ( ref mut t) => WritableDst :: Raw ( t) ,
26422641 }
26432642 }
26442643
26452644 fn supports_color ( & self ) -> bool {
26462645 match * self {
26472646 Self :: Terminal ( ref stream) => stream. supports_color ( ) ,
26482647 Self :: Buffered ( ref buffer) => buffer. buffer ( ) . supports_color ( ) ,
2649- Self :: Raw ( _ , supports_color ) => supports_color,
2648+ Self :: Raw ( ref writer ) => writer . supports_color ( ) ,
26502649 }
26512650 }
26522651}
@@ -2706,17 +2705,15 @@ impl<'a> WritableDst<'a> {
27062705 match * self {
27072706 WritableDst :: Terminal ( ref mut t) => t. set_color ( color) ,
27082707 WritableDst :: Buffered ( _, ref mut t) => t. set_color ( color) ,
2709- WritableDst :: ColoredRaw ( ref mut t) => t. set_color ( color) ,
2710- WritableDst :: Raw ( _) => Ok ( ( ) ) ,
2708+ WritableDst :: Raw ( ref mut t) => t. set_color ( color) ,
27112709 }
27122710 }
27132711
27142712 fn reset ( & mut self ) -> io:: Result < ( ) > {
27152713 match * self {
27162714 WritableDst :: Terminal ( ref mut t) => t. reset ( ) ,
27172715 WritableDst :: Buffered ( _, ref mut t) => t. reset ( ) ,
2718- WritableDst :: ColoredRaw ( ref mut t) => t. reset ( ) ,
2719- WritableDst :: Raw ( _) => Ok ( ( ) ) ,
2716+ WritableDst :: Raw ( ref mut t) => t. reset ( ) ,
27202717 }
27212718 }
27222719}
@@ -2727,7 +2724,6 @@ impl<'a> Write for WritableDst<'a> {
27272724 WritableDst :: Terminal ( ref mut t) => t. write ( bytes) ,
27282725 WritableDst :: Buffered ( _, ref mut buf) => buf. write ( bytes) ,
27292726 WritableDst :: Raw ( ref mut w) => w. write ( bytes) ,
2730- WritableDst :: ColoredRaw ( ref mut t) => t. write ( bytes) ,
27312727 }
27322728 }
27332729
@@ -2736,7 +2732,6 @@ impl<'a> Write for WritableDst<'a> {
27362732 WritableDst :: Terminal ( ref mut t) => t. flush ( ) ,
27372733 WritableDst :: Buffered ( _, ref mut buf) => buf. flush ( ) ,
27382734 WritableDst :: Raw ( ref mut w) => w. flush ( ) ,
2739- WritableDst :: ColoredRaw ( ref mut w) => w. flush ( ) ,
27402735 }
27412736 }
27422737}
0 commit comments