Title: IDLE: Have the shell mimic terminal handling of \r and \b control characters in outputs
Type: enhancement Stage: patch review
Components: IDLE Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: cheryl.sabella, rhettinger, taleinat, terry.reedy
Priority: normal Keywords: patch

Created on 2019-08-12 06:52 by taleinat, last changed 2019-08-12 07:00 by taleinat.

Pull Requests
URL Status Linked Edit
PR 15211 open taleinat, 2019-08-12 06:54
Messages (2)
msg349440 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-08-12 06:52
IDLE's shell doesn't currently handle \r and \b in any special way; they are written the the Tk Text widget which displays them in strange, system-dependent ways.

These are often used to show continuously updated progress, e.g. in text-based progress bars, without flooding the output, since they allow overwriting previously written output. If we implement handling for \r and \b, progress indicators such as these could finally work properly in IDLE's shell.

To make things worse, Tk's Text widget becomes increasingly slow when it wraps very long lines. IDLE's shell must wrap lines, and is therefore prone to such slowdowns. Attempting to show updating progress info using \r or \b results in such increasingly long lines of output, eventually slowing IDLE's shell down to a crawl. (The recent addition of squeezing of long outputs help for the case of single, very long outputs, but not with many short strings written on a single line.)

As a recent example, the basic Tensorflow tutorial shows such progress information for several of its stages. Due to the lack of handling for these control characters, it is practically unusable in the IDLE shell due to this. See issue #37762 about this.

Since the shell aims to closely emulate using an interactive terminal session, and since showing progress is so common in interactive work, I propose to add special handling of these two control characters in outputs written to the shell window.

Related issues:

#23220: Documents input/output effects of how IDLE runs user code (originally titled "IDLE does not display \b backspace correctly")

#24572: IDLE Text Output With ASCII Control Codes Not Working (marked as duplicate of #23220)

#37762: IDLE very slow due a super long line output in chunks

StackOverflow: what is the difference between cmd and idle when using tqdm? (
msg349443 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-08-12 07:00
See PR GH-15211 with a working implementation.
Date User Action Args
2019-08-12 07:00:02taleinatsetmessages: + msg349443
2019-08-12 06:54:09taleinatsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14945
2019-08-12 06:52:53taleinatcreate