@@ -35,7 +35,7 @@ class ColorDepth(str, Enum):
3535 TRUE_COLOR  =  DEPTH_24_BIT 
3636
3737 @classmethod  
38-  def  default (cls , term : Optional [str ] =  None ) ->  "ColorDepth" :
38+  def  local_default (cls , term : Optional [str ] =  None ) ->  "ColorDepth" :
3939 """ 
4040 Return the default color depth, according to the $TERM value. 
4141
@@ -50,25 +50,46 @@ def default(cls, term: Optional[str] = None) -> "ColorDepth":
5050 """ 
5151 # Take `TERM` value from environment variable if nothing was passed. 
5252 if  term  is  None :
53-  term  =  os .environ .get ("TERM" , "" )
53+  term  =  os .environ .get ("TERM" )
54+ 
55+  if  is_dumb_terminal (term ):
56+  return  cls .DEPTH_1_BIT 
57+ 
58+  # Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable. 
59+  all_values  =  [i .value  for  i  in  ColorDepth ]
60+  if  os .environ .get ("PROMPT_TOOLKIT_COLOR_DEPTH" ) in  all_values :
61+  return  cls (os .environ ["PROMPT_TOOLKIT_COLOR_DEPTH" ])
62+ 
63+  return  cls .windows_default () if  is_windows () else  cls .vt100_default (term )
64+ 
65+  @classmethod  
66+  def  vt100_default (cls , term : Optional [str ] =  None ) ->  "ColorDepth" :
67+  """Return the default color depth for a vt100 terminal, according to the term 
68+  value. 
69+ 
70+  Contrary to `local_default`, this method doesn't take the local system into 
71+  account. 
72+  """ 
73+  if  term  is  None :
74+  return  cls .DEFAULT 
5475
5576 if  is_dumb_terminal (term ):
5677 return  cls .DEPTH_1_BIT 
5778
5879 if  term  in  ("linux" , "eterm-color" ):
5980 return  cls .DEPTH_4_BIT 
6081
82+  return  cls .DEFAULT 
83+ 
84+  @classmethod  
85+  def  windows_default (cls ) ->  "ColorDepth" :
86+  """Return the default color depth for a windows terminal. 
87+ 
88+  Contrary to `local_default`, this method doesn't take the local system into 
89+  account. 
90+  """ 
6191 # For now, always use 4 bit color on Windows 10 by default, even when 
6292 # vt100 escape sequences with ENABLE_VIRTUAL_TERMINAL_PROCESSING are 
6393 # supported. We don't have a reliable way yet to know whether our 
6494 # console supports true color or only 4-bit. 
65-  if  is_windows () and  "PROMPT_TOOLKIT_COLOR_DEPTH"  not  in os .environ :
66-  return  cls .DEPTH_4_BIT 
67- 
68-  # Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable. 
69-  all_values  =  [i .value  for  i  in  ColorDepth ]
70- 
71-  if  os .environ .get ("PROMPT_TOOLKIT_COLOR_DEPTH" ) in  all_values :
72-  return  cls (os .environ ["PROMPT_TOOLKIT_COLOR_DEPTH" ])
73- 
74-  return  cls .DEPTH_8_BIT 
95+  return  cls .DEPTH_4_BIT 
0 commit comments