@@ -2,6 +2,7 @@ use std::fmt;
22use std:: io:: IsTerminal ;
33use std:: io:: prelude:: * ;
44
5+ use annotate_snippets:: renderer:: DecorStyle ;
56use annotate_snippets:: { Renderer , Report } ;
67use anstream:: AutoStream ;
78use anstyle:: Style ;
@@ -57,6 +58,7 @@ impl Shell {
5758 stdout_unicode : supports_unicode ( & std:: io:: stdout ( ) ) ,
5859 stderr_unicode : supports_unicode ( & std:: io:: stderr ( ) ) ,
5960 stderr_term_integration : supports_term_integration ( & std:: io:: stderr ( ) ) ,
61+ unstable_flags_rustc_unicode : false ,
6062 } ,
6163 verbosity : Verbosity :: Verbose ,
6264 needs_clear : false ,
@@ -380,6 +382,27 @@ impl Shell {
380382 Some ( url)
381383 }
382384
385+ fn unstable_flags_rustc_unicode ( & self ) -> bool {
386+ match & self . output {
387+ ShellOut :: Write ( _) => false ,
388+ ShellOut :: Stream {
389+ unstable_flags_rustc_unicode,
390+ ..
391+ } => * unstable_flags_rustc_unicode,
392+ }
393+ }
394+
395+ pub ( crate ) fn set_unstable_flags_rustc_unicode ( & mut self , yes : bool ) -> CargoResult < ( ) > {
396+ if let ShellOut :: Stream {
397+ unstable_flags_rustc_unicode,
398+ ..
399+ } = & mut self . output
400+ {
401+ * unstable_flags_rustc_unicode = yes;
402+ }
403+ Ok ( ( ) )
404+ }
405+
383406 /// Prints a message to stderr and translates ANSI escape code into console colors.
384407 pub fn print_ansi_stderr ( & mut self , message : & [ u8 ] ) -> CargoResult < ( ) > {
385408 if self . needs_clear {
@@ -419,7 +442,15 @@ impl Shell {
419442 . err_width ( )
420443 . diagnostic_terminal_width ( )
421444 . unwrap_or ( annotate_snippets:: renderer:: DEFAULT_TERM_WIDTH ) ;
422- let rendered = Renderer :: styled ( ) . term_width ( term_width) . render ( report) ;
445+ let decor_style = if self . err_unicode ( ) && self . unstable_flags_rustc_unicode ( ) {
446+ DecorStyle :: Unicode
447+ } else {
448+ DecorStyle :: Ascii
449+ } ;
450+ let rendered = Renderer :: styled ( )
451+ . term_width ( term_width)
452+ . decor_style ( decor_style)
453+ . render ( report) ;
423454 self . err ( ) . write_all ( rendered. as_bytes ( ) ) ?;
424455 self . err ( ) . write_all ( b"\n " ) ?;
425456 Ok ( ( ) )
@@ -446,6 +477,7 @@ enum ShellOut {
446477 stdout_unicode : bool ,
447478 stderr_unicode : bool ,
448479 stderr_term_integration : bool ,
480+ unstable_flags_rustc_unicode : bool ,
449481 } ,
450482}
451483
0 commit comments