@@ -35,9 +35,9 @@ class ColorDepth(str, Enum):
3535 TRUE_COLOR  =  DEPTH_24_BIT 
3636
3737 @classmethod  
38-  def  default (cls , term : Optional [str ] =  None ) ->  "ColorDepth" :
38+  def  default (cls , output : Optional [Output ] =  None ) ->  "ColorDepth" :
3939 """ 
40-  Return the default color depth, according to the $TERM value . 
40+  Return the default color depth, according to the provided output . 
4141
4242 We prefer 256 colors almost always, because this is what most terminals 
4343 support these days, and is a good default. 
@@ -46,9 +46,12 @@ def default(cls, term: Optional[str] = None) -> "ColorDepth":
4646 override this outcome. This is a way to enforce a certain color depth 
4747 in all prompt_toolkit applications. 
4848
49-  If no `term` parameter is given, we use the $TERM environment variable. 
49+  If no `output` parameter is given or it does not provide a corresponding 
50+  `term`, we use the $TERM environment variable. 
5051 """ 
5152 # Take `TERM` value from environment variable if nothing was passed. 
53+  term  =  getattr (output , "term" , None )
54+ 
5255 if  term  is  None :
5356 term  =  os .environ .get ("TERM" , "" )
5457
@@ -62,7 +65,7 @@ def default(cls, term: Optional[str] = None) -> "ColorDepth":
6265 # vt100 escape sequences with ENABLE_VIRTUAL_TERMINAL_PROCESSING are 
6366 # supported. We don't have a reliable way yet to know whether our 
6467 # console supports true color or only 4-bit. 
65-  if  is_windows () and  "PROMPT_TOOLKIT_COLOR_DEPTH"  not  in os .environ :
68+  if  output . is_windows () and  "PROMPT_TOOLKIT_COLOR_DEPTH"  not  in os .environ :
6669 return  cls .DEPTH_4_BIT 
6770
6871 # Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable. 
0 commit comments