@@ -33,6 +33,7 @@ class Windows10_Output:
3333 def __init__ (
3434 self , stdout : TextIO , default_color_depth : ColorDepth | None = None
3535 ) -> None :
36+ self .default_color_depth = default_color_depth
3637 self .win32_output = Win32Output (stdout , default_color_depth = default_color_depth )
3738 self .vt100_output = Vt100_Output (
3839 stdout , lambda : Size (0 , 0 ), default_color_depth = default_color_depth
@@ -74,12 +75,30 @@ def __getattr__(self, name: str) -> Any:
7475 "get_win32_screen_buffer_info" ,
7576 "enable_bracketed_paste" ,
7677 "disable_bracketed_paste" ,
77- "get_default_color_depth" ,
7878 ):
7979 return getattr (self .win32_output , name )
8080 else :
8181 return getattr (self .vt100_output , name )
8282
83+ def get_default_color_depth (self ) -> ColorDepth :
84+ """
85+ Return the default color depth for a windows terminal.
86+
87+ Contrary to the Vt100 implementation, this doesn't depend on a $TERM
88+ variable.
89+ """
90+ if self .default_color_depth is not None :
91+ return self .default_color_depth
92+
93+ # Previously, we used `DEPTH_4_BIT`, even on Windows 10. This was
94+ # because true color support was added after "Console Virtual Terminal
95+ # Sequences" support was added, and there was no good way to detect
96+ # what support was given.
97+ # 24bit color support was added in 2016, so let's assume it's safe to
98+ # take that as a default:
99+ # https://devblogs.microsoft.com/commandline/24-bit-color-in-the-windows-console/
100+ return ColorDepth .TRUE_COLOR
101+
83102
84103Output .register (Windows10_Output )
85104
0 commit comments