@@ -47,6 +47,13 @@ impl StdStreamDest<io::Stdout, io::Stderr> {
47
47
StdStreamDest :: Stderr ( stream) => StdStreamDest :: Stderr ( stream. lock ( ) ) ,
48
48
}
49
49
}
50
+
51
+ fn stream_type ( & self ) -> StdStream {
52
+ match self {
53
+ StdStreamDest :: Stdout ( _) => StdStream :: Stdout ,
54
+ StdStreamDest :: Stderr ( _) => StdStream :: Stderr ,
55
+ }
56
+ }
50
57
}
51
58
52
59
macro_rules! impl_write_for_dest {
@@ -79,7 +86,6 @@ impl_write_for_dest!(StdStreamDest<io::StdoutLock<'_>, io::StderrLock<'_>>);
79
86
pub struct StdStreamSink {
80
87
common_impl : helper:: CommonImpl ,
81
88
dest : StdStreamDest < io:: Stdout , io:: Stderr > ,
82
- atty_stream : atty:: Stream ,
83
89
should_render_style : bool ,
84
90
level_style_codes : LevelStyleCodes ,
85
91
}
@@ -116,14 +122,20 @@ impl StdStreamSink {
116
122
117
123
/// Sets the style mode.
118
124
pub fn set_style_mode ( & mut self , style_mode : StyleMode ) {
119
- self . should_render_style = Self :: should_render_style ( style_mode, self . atty_stream ) ;
125
+ self . should_render_style = Self :: should_render_style ( style_mode, self . dest . stream_type ( ) ) ;
120
126
}
121
127
122
128
#[ must_use]
123
- fn should_render_style ( style_mode : StyleMode , atty_stream : atty:: Stream ) -> bool {
129
+ fn should_render_style ( style_mode : StyleMode , stream : StdStream ) -> bool {
130
+ use is_terminal:: IsTerminal ;
131
+ let is_terminal = match stream {
132
+ StdStream :: Stdout => io:: stdout ( ) . is_terminal ( ) ,
133
+ StdStream :: Stderr => io:: stderr ( ) . is_terminal ( ) ,
134
+ } ;
135
+
124
136
match style_mode {
125
137
StyleMode :: Always => true ,
126
- StyleMode :: Auto => atty :: is ( atty_stream ) && enable_ansi_escape_sequences ( ) ,
138
+ StyleMode :: Auto => is_terminal && enable_ansi_escape_sequences ( ) ,
127
139
StyleMode :: Never => false ,
128
140
}
129
141
}
@@ -263,16 +275,13 @@ impl StdStreamSinkBuilder<()> {
263
275
impl StdStreamSinkBuilder < StdStream > {
264
276
/// Builds a [`StdStreamSink`].
265
277
pub fn build ( self ) -> Result < StdStreamSink > {
266
- let atty_stream = match self . std_stream {
267
- StdStream :: Stdout => atty:: Stream :: Stdout ,
268
- StdStream :: Stderr => atty:: Stream :: Stderr ,
269
- } ;
270
-
271
278
Ok ( StdStreamSink {
272
279
common_impl : helper:: CommonImpl :: from_builder ( self . common_builder_impl ) ,
273
280
dest : StdStreamDest :: new ( self . std_stream ) ,
274
- atty_stream,
275
- should_render_style : StdStreamSink :: should_render_style ( self . style_mode , atty_stream) ,
281
+ should_render_style : StdStreamSink :: should_render_style (
282
+ self . style_mode ,
283
+ self . std_stream ,
284
+ ) ,
276
285
level_style_codes : LevelStyleCodes :: default ( ) ,
277
286
} )
278
287
}
0 commit comments