From 34d62382e1e9d176d7318e8ffebaf8cc8352153d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Dec 2024 13:19:41 +0100 Subject: [PATCH 1/2] gh-127060: Disable traceback colors in IDLE Set TERM environment variable to "dumb" to disable traceback colors in IDLE, since IDLE doesn't understand ANSI escape sequences. --- Lib/idlelib/pyshell.py | 3 +++ .../Library/2024-12-17-13-21-52.gh-issue-127060.mv2bX6.rst | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-12-17-13-21-52.gh-issue-127060.mv2bX6.rst diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index e882c6cb3b8d19..6a4779a2e1f10c 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -1596,6 +1596,9 @@ def main(): enable_edit = enable_edit or edit_start enable_shell = enable_shell or not enable_edit + # gh-127060: Disable traceback colors + os.environ['TERM'] = 'dumb' + # Setup root. Don't break user code run in IDLE process. # Don't change environment when testing. if use_subprocess and not testing: diff --git a/Misc/NEWS.d/next/Library/2024-12-17-13-21-52.gh-issue-127060.mv2bX6.rst b/Misc/NEWS.d/next/Library/2024-12-17-13-21-52.gh-issue-127060.mv2bX6.rst new file mode 100644 index 00000000000000..1da89e7a282147 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-12-17-13-21-52.gh-issue-127060.mv2bX6.rst @@ -0,0 +1,2 @@ +Set TERM environment variable to "dumb" to disable traceback colors in IDLE, +since IDLE doesn't understand ANSI escape sequences. Patch by Victor Stinner. From bd8b5892b1007bfbd032e360a4e3efdd01a9c8b4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Dec 2024 14:31:58 +0100 Subject: [PATCH 2/2] Only set TERM in the subprocess --- Lib/idlelib/pyshell.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index 6a4779a2e1f10c..66fbbd4a97b7af 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -424,7 +424,9 @@ def __init__(self, tkconsole): def spawn_subprocess(self): if self.subprocess_arglist is None: self.subprocess_arglist = self.build_subprocess_arglist() - self.rpcsubproc = subprocess.Popen(self.subprocess_arglist) + # gh-127060: Disable traceback colors + env = dict(os.environ, TERM='dumb') + self.rpcsubproc = subprocess.Popen(self.subprocess_arglist, env=env) def build_subprocess_arglist(self): assert (self.port!=0), ( @@ -1596,9 +1598,6 @@ def main(): enable_edit = enable_edit or edit_start enable_shell = enable_shell or not enable_edit - # gh-127060: Disable traceback colors - os.environ['TERM'] = 'dumb' - # Setup root. Don't break user code run in IDLE process. # Don't change environment when testing. if use_subprocess and not testing: