Skip to content

Commit

Permalink
Support the NO_COLOR environment variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanslenders committed Jul 4, 2023
1 parent 0bbc653 commit 0151f23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/prompt_toolkit/output/color_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def from_env(cls) -> ColorDepth | None:
This is a way to enforce a certain color depth in all prompt_toolkit
applications.
"""
# Disable color if a `NO_COLOR` environment variable is set.
# See: https://no-color.org/
if os.environ.get("NO_COLOR"):
return cls.DEPTH_1_BIT

# Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable.
all_values = [i.value for i in ColorDepth]
if os.environ.get("PROMPT_TOOLKIT_COLOR_DEPTH") in all_values:
Expand Down
4 changes: 3 additions & 1 deletion src/prompt_toolkit/styles/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
# Completions menu.
("completion-menu", "bg:#bbbbbb #000000"),
("completion-menu.completion", ""),
("completion-menu.completion.current", "bg:#888888 #ffffff"),
# (Note: for the current completion, we use 'reverse' on top of fg/bg
# colors. This is to have proper rendering with NO_COLOR=1).
("completion-menu.completion.current", "fg:#888888 bg:#ffffff reverse"),
("completion-menu.meta.completion", "bg:#999999 #000000"),
("completion-menu.meta.completion.current", "bg:#aaaaaa #000000"),
("completion-menu.multi-column-meta", "bg:#aaaaaa #000000"),
Expand Down

0 comments on commit 0151f23

Please sign in to comment.