Skip to content

Commit

Permalink
Use 24-bit true color now by default on Windows 10/11.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanslenders committed Feb 27, 2023
1 parent e64c740 commit 0e7b3e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/prompt_toolkit/output/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,6 @@ def get_default_color_depth(self) -> ColorDepth:
if self.default_color_depth is not None:
return self.default_color_depth

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


Expand Down
21 changes: 20 additions & 1 deletion src/prompt_toolkit/output/windows10.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Windows10_Output:
def __init__(
self, stdout: TextIO, default_color_depth: ColorDepth | None = None
) -> None:
self.default_color_depth = default_color_depth
self.win32_output = Win32Output(stdout, default_color_depth=default_color_depth)
self.vt100_output = Vt100_Output(
stdout, lambda: Size(0, 0), default_color_depth=default_color_depth
Expand Down Expand Up @@ -74,12 +75,30 @@ def __getattr__(self, name: str) -> Any:
"get_win32_screen_buffer_info",
"enable_bracketed_paste",
"disable_bracketed_paste",
"get_default_color_depth",
):
return getattr(self.win32_output, name)
else:
return getattr(self.vt100_output, name)

def get_default_color_depth(self) -> ColorDepth:
"""
Return the default color depth for a windows terminal.
Contrary to the Vt100 implementation, this doesn't depend on a $TERM
variable.
"""
if self.default_color_depth is not None:
return self.default_color_depth

# Previously, we used `DEPTH_4_BIT`, even on Windows 10. This was
# because true color support was added after "Console Virtual Terminal
# Sequences" support was added, and there was no good way to detect
# what support was given.
# 24bit color support was added in 2016, so let's assume it's safe to
# take that as a default:
# https://devblogs.microsoft.com/commandline/24-bit-color-in-the-windows-console/
return ColorDepth.TRUE_COLOR


Output.register(Windows10_Output)

Expand Down

0 comments on commit 0e7b3e0

Please sign in to comment.