@@ -1055,6 +1055,9 @@ impl Config {
1055
1055
if let Some ( hyperlinks) = term. hyperlinks {
1056
1056
self . shell ( ) . set_hyperlinks ( hyperlinks) ?;
1057
1057
}
1058
+ if let Some ( charset) = term. charset {
1059
+ self . shell ( ) . set_charset ( charset) ?;
1060
+ }
1058
1061
self . progress_config = term. progress . unwrap_or_default ( ) ;
1059
1062
self . extra_verbose = extra_verbose;
1060
1063
self . frozen = frozen;
@@ -2605,11 +2608,53 @@ struct TermConfig {
2605
2608
quiet : Option < bool > ,
2606
2609
color : Option < String > ,
2607
2610
hyperlinks : Option < bool > ,
2611
+ charset : Option < Charset > ,
2608
2612
#[ serde( default ) ]
2609
2613
#[ serde( deserialize_with = "progress_or_string" ) ]
2610
2614
progress : Option < ProgressConfig > ,
2611
2615
}
2612
2616
2617
+ #[ derive( Copy , Clone , Debug ) ]
2618
+ pub enum Charset {
2619
+ Utf8 ,
2620
+ Ascii ,
2621
+ }
2622
+
2623
+ impl Charset {
2624
+ pub fn auto_with ( stream : & dyn std:: io:: IsTerminal ) -> Self {
2625
+ if !stream. is_terminal ( ) || supports_unicode:: supports_unicode ( ) {
2626
+ Self :: Utf8
2627
+ } else {
2628
+ Self :: Ascii
2629
+ }
2630
+ }
2631
+ }
2632
+
2633
+ impl std:: str:: FromStr for Charset {
2634
+ type Err = & ' static str ;
2635
+
2636
+ fn from_str ( s : & str ) -> Result < Charset , & ' static str > {
2637
+ match s {
2638
+ "utf8" => Ok ( Charset :: Utf8 ) ,
2639
+ "ascii" => Ok ( Charset :: Ascii ) ,
2640
+ _ => Err ( "invalid charset" ) ,
2641
+ }
2642
+ }
2643
+ }
2644
+
2645
+ impl < ' de > Deserialize < ' de > for Charset {
2646
+ fn deserialize < D > ( d : D ) -> Result < Self , D :: Error >
2647
+ where
2648
+ D : serde:: de:: Deserializer < ' de > ,
2649
+ {
2650
+ use serde:: de:: Error as _;
2651
+ UntaggedEnumVisitor :: new ( )
2652
+ . expecting ( "a charset" )
2653
+ . string ( |value| value. parse ( ) . map_err ( serde_untagged:: de:: Error :: custom) )
2654
+ . deserialize ( d)
2655
+ }
2656
+ }
2657
+
2613
2658
#[ derive( Debug , Default , Deserialize ) ]
2614
2659
pub struct ProgressConfig {
2615
2660
pub when : ProgressWhen ,
0 commit comments