Skip to content

Commit

Permalink
avoid FORCE_COLOR implying a terminal in Jupyter
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Feb 12, 2023
1 parent b89d036 commit 45f62a8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions rich/console.py
Expand Up @@ -711,11 +711,6 @@ def __init__(
self._force_terminal = None
if force_terminal is not None:
self._force_terminal = force_terminal
else:
# If FORCE_COLOR env var has any value at all, we force terminal.
force_color = self._environ.get("FORCE_COLOR")
if force_color is not None:
self._force_terminal = True

self._file = file
self.quiet = quiet
Expand Down Expand Up @@ -949,6 +944,15 @@ def is_terminal(self) -> bool:
# Return False for Idle which claims to be a tty but can't handle ansi codes
return False

if self.is_jupyter:
# return False for Jupyter, which may have FORCE_COLOR set
return False

# If FORCE_COLOR env var has any value at all, we assume a terminal.
force_color = self._environ.get("FORCE_COLOR")
if force_color is not None:
self._force_terminal = True

isatty: Optional[Callable[[], bool]] = getattr(self.file, "isatty", None)
try:
return False if isatty is None else isatty()
Expand Down

0 comments on commit 45f62a8

Please sign in to comment.