Skip to content

Commit 0e7b3e0

Browse files
Use 24-bit true color now by default on Windows 10/11.
1 parent e64c740 commit 0e7b3e0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/prompt_toolkit/output/win32.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,6 @@ def get_default_color_depth(self) -> ColorDepth:
525525
if self.default_color_depth is not None:
526526
return self.default_color_depth
527527

528-
# For now, by default, always use 4 bit color on Windows 10 by default,
529-
# even when vt100 escape sequences with
530-
# ENABLE_VIRTUAL_TERMINAL_PROCESSING are supported. We don't have a
531-
# reliable way yet to know whether our console supports true color or
532-
# only 4-bit.
533528
return ColorDepth.DEPTH_4_BIT
534529

535530

src/prompt_toolkit/output/windows10.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

84103
Output.register(Windows10_Output)
85104

0 commit comments

Comments
 (0)