diff --git a/CHANGELOG.md b/CHANGELOG.md index b82884a77..7ce176a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed markup escaping issue https://github.com/Textualize/rich/issues/2187 - Safari - Box appearing around SVG export https://github.com/Textualize/rich/pull/2201 - Fixed recursion error in Jupyter progress bars https://github.com/Textualize/rich/issues/2047 +- Fix crash on IDLE and forced is_terminal detection to False because IDLE can't do escape codes https://github.com/Textualize/rich/issues/2222 ### Changed diff --git a/rich/console.py b/rich/console.py index d0b2d44c4..5a0769408 100644 --- a/rich/console.py +++ b/rich/console.py @@ -915,6 +915,13 @@ def is_terminal(self) -> bool: """ if self._force_terminal is not None: return self._force_terminal + + if hasattr(sys.stdin, "__module__") and sys.stdin.__module__.startswith( + "idlelib" + ): + # Return False for Idle which claims to be a tty but can't handle ansi codes + return False + isatty: Optional[Callable[[], bool]] = getattr(self.file, "isatty", None) try: return False if isatty is None else isatty()