diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-06 18:19:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-06 18:19:30 (GMT) |
commit | 084ba337a93facac4694459b460cf329d58d2b62 (patch) | |
tree | 05b9bf652346736404bc477672e9e15342a5f3fe /Lib/idlelib/pyshell.py | |
parent | 1e2707d7e82aedf73c59772bc7aa228286323c3c (diff) | |
download | cpython-084ba337a93facac4694459b460cf329d58d2b62.zip cpython-084ba337a93facac4694459b460cf329d58d2b62.tar.gz cpython-084ba337a93facac4694459b460cf329d58d2b62.tar.bz2 |
bpo-38041: Refine IDLE Shell restart lines. (GH-15709)
Restart lines now always start with '=' and never end with ' ' and fill the width of the window unless that would require ending with ' ', which could be wrapped by itself and possible confusing the user.
(cherry picked from commit 38da805d563422cf1bb9cd9be24c73806840fe30)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/pyshell.py')
-rwxr-xr-x | Lib/idlelib/pyshell.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index ea94655..08716a9 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -387,6 +387,19 @@ class MyRPCClient(rpc.RPCClient): "Override the base class - just re-raise EOFError" raise EOFError +def restart_line(width, filename): # See bpo-38141. + """Return width long restart line formatted with filename. + + Fill line with balanced '='s, with any extras and at least one at + the beginning. Do not end with a trailing space. + """ + tag = f"= RESTART: {filename or 'Shell'} =" + if width >= len(tag): + div, mod = divmod((width -len(tag)), 2) + return f"{(div+mod)*'='}{tag}{div*'='}" + else: + return tag[:-2] # Remove ' ='. + class ModifiedInterpreter(InteractiveInterpreter): @@ -491,9 +504,8 @@ class ModifiedInterpreter(InteractiveInterpreter): console.stop_readline() # annotate restart in shell window and mark it console.text.delete("iomark", "end-1c") - tag = 'RESTART: ' + (filename if filename else 'Shell') - halfbar = ((int(console.width) -len(tag) - 4) // 2) * '=' - console.write("\n{0} {1} {0}".format(halfbar, tag)) + console.write('\n') + console.write(restart_line(console.width, filename)) console.text.mark_set("restart", "end-1c") console.text.mark_gravity("restart", "left") if not filename: |