Skip to content

Commit 0151f23

Browse files
Support the NO_COLOR environment variable.
See: https://no-color.org/
1 parent 0bbc653 commit 0151f23

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/prompt_toolkit/output/color_depth.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def from_env(cls) -> ColorDepth | None:
4242
This is a way to enforce a certain color depth in all prompt_toolkit
4343
applications.
4444
"""
45+
# Disable color if a `NO_COLOR` environment variable is set.
46+
# See: https://no-color.org/
47+
if os.environ.get("NO_COLOR"):
48+
return cls.DEPTH_1_BIT
49+
4550
# Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable.
4651
all_values = [i.value for i in ColorDepth]
4752
if os.environ.get("PROMPT_TOOLKIT_COLOR_DEPTH") in all_values:

src/prompt_toolkit/styles/defaults.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
# Completions menu.
6464
("completion-menu", "bg:#bbbbbb #000000"),
6565
("completion-menu.completion", ""),
66-
("completion-menu.completion.current", "bg:#888888 #ffffff"),
66+
# (Note: for the current completion, we use 'reverse' on top of fg/bg
67+
# colors. This is to have proper rendering with NO_COLOR=1).
68+
("completion-menu.completion.current", "fg:#888888 bg:#ffffff reverse"),
6769
("completion-menu.meta.completion", "bg:#999999 #000000"),
6870
("completion-menu.meta.completion.current", "bg:#aaaaaa #000000"),
6971
("completion-menu.multi-column-meta", "bg:#aaaaaa #000000"),

0 commit comments

Comments
 (0)