File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use alloc:: sync:: Arc ;
22use core:: fmt:: { Debug , Display } ;
3+ use std:: env;
34use std:: io:: { self , Read , Write } ;
45#[ cfg( any( unix, all( target_os = "wasi" , target_env = "p1" ) ) ) ]
56use std:: os:: fd:: { AsRawFd , RawFd } ;
@@ -576,7 +577,16 @@ impl Term {
576577/// Native windows terminals typically do not set the `TERM` environment variable.
577578#[ inline]
578579pub fn is_dumb ( ) -> bool {
579- is_a_dumb_terminal ( )
580+ #[ cfg( unix) ]
581+ let default = true ;
582+
583+ #[ cfg( not( unix) ) ]
584+ let default = false ;
585+
586+ match env:: var ( "TERM" ) {
587+ Ok ( term) => term == "dumb" ,
588+ Err ( _) => default,
589+ }
580590}
581591
582592/// A fast way to check if the application has a user attended for stdout.
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use std::os::fd::{AsRawFd, RawFd};
99#[ cfg( not( target_os = "macos" ) ) ]
1010use std:: sync:: OnceLock ;
1111
12+ use crate :: is_dumb;
1213use crate :: kb:: Key ;
1314use crate :: term:: Term ;
1415
@@ -21,13 +22,6 @@ pub(crate) fn is_a_terminal(out: &impl AsRawFd) -> bool {
2122 unsafe { libc:: isatty ( out. as_raw_fd ( ) ) != 0 }
2223}
2324
24- pub ( crate ) fn is_a_dumb_terminal ( ) -> bool {
25- match env:: var ( "TERM" ) {
26- Ok ( term) => term == "dumb" ,
27- Err ( _) => true ,
28- }
29- }
30-
3125pub ( crate ) fn is_a_color_terminal ( out : & Term ) -> bool {
3226 if !is_a_terminal ( out) {
3327 return false ;
@@ -37,7 +31,7 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
3731 return false ;
3832 }
3933
40- !is_a_dumb_terminal ( )
34+ !is_dumb ( )
4135}
4236
4337pub ( crate ) fn is_a_true_color_terminal ( out : & Term ) -> bool {
Original file line number Diff line number Diff line change @@ -21,11 +21,6 @@ pub(crate) fn is_a_terminal(_out: &Term) -> bool {
2121 }
2222}
2323
24- #[ inline]
25- pub ( crate ) fn is_a_dumb_terminal ( ) -> bool {
26- false
27- }
28-
2924#[ inline]
3025pub ( crate ) fn is_a_color_terminal ( _out : & Term ) -> bool {
3126 // We currently never report color terminals. For discussion see
Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ use windows_sys::Win32::System::Console::{
2424} ;
2525use windows_sys:: Win32 :: UI :: Input :: KeyboardAndMouse :: VIRTUAL_KEY ;
2626
27- use crate :: common_term;
2827use crate :: kb:: Key ;
2928use crate :: term:: { Term , TermTarget } ;
29+ use crate :: { common_term, is_dumb} ;
3030
3131#[ cfg( feature = "windows-console-colors" ) ]
3232mod colors;
@@ -59,16 +59,6 @@ pub(crate) fn is_a_terminal(out: &Term) -> bool {
5959 msys_tty_on ( out)
6060}
6161
62- pub ( crate ) fn is_a_dumb_terminal ( ) -> bool {
63- // Native windows terminals typically do not set the TERM.
64- // We can only assume that if it is explicitly set to `dumb` then it is a dumb terminal.
65- // Otherwise, we assume it is not.
66- match env:: var ( "TERM" ) {
67- Ok ( term) => term == "dumb" ,
68- Err ( _) => false ,
69- }
70- }
71-
7262pub ( crate ) fn is_a_color_terminal ( out : & Term ) -> bool {
7363 if !is_a_terminal ( out) {
7464 return false ;
@@ -77,7 +67,7 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
7767 return false ;
7868 }
7969 if msys_tty_on ( out) {
80- return !is_a_dumb_terminal ( ) ;
70+ return !is_dumb ( ) ;
8171 }
8272 enable_ansi_on ( out)
8373}
You can’t perform that action at this time.
0 commit comments