[Python-checkins] bpo-38041: Refine IDLE Shell restart lines. (GH-15709)

Miss Islington (bot) webhook-mailer at python.org
Fri Sep 6 14:14:59 EDT 2019


https://github.com/python/cpython/commit/4009a8522d774c36918005527dfb0975f389c8c2
commit: 4009a8522d774c36918005527dfb0975f389c8c2
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019年09月06日T11:14:49-07:00
summary:
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 at udel.edu>
files:
A Misc/NEWS.d/next/IDLE/2019-09-05-23-12-13.bpo-38041.nxmGGK.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/idle_test/test_pyshell.py
M Lib/idlelib/pyshell.py
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index c9e846a6fba6..559ffd0cf4f3 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,10 @@ Released on 2019年10月20日?
 ======================================
 
 
+bpo-38401: Shell restart lines now fill the window width, always start
+with '=', and avoid wrapping unnecessarily. The line will still wrap
+if the included file name is long relative to the width.
+
 bpo-37092: Add mousewheel scrolling for IDLE module, path, and stack
 browsers. Patch by George Zhang.
 
diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py
index 581444ca5ef2..4a096676f257 100644
--- a/Lib/idlelib/idle_test/test_pyshell.py
+++ b/Lib/idlelib/idle_test/test_pyshell.py
@@ -7,6 +7,28 @@
 from tkinter import Tk
 
 
+class FunctionTest(unittest.TestCase):
+ # Test stand-alone module level non-gui functions.
+
+ def test_restart_line_wide(self):
+ eq = self.assertEqual
+ for file, mul, extra in (('', 22, ''), ('finame', 21, '=')):
+ width = 60
+ bar = mul * '='
+ with self.subTest(file=file, bar=bar):
+ file = file or 'Shell'
+ line = pyshell.restart_line(width, file)
+ eq(len(line), width)
+ eq(line, f"{bar+extra} RESTART: {file} {bar}")
+
+ def test_restart_line_narrow(self):
+ expect, taglen = "= RESTART: Shell", 16
+ for width in (taglen-1, taglen, taglen+1):
+ with self.subTest(width=width):
+ self.assertEqual(pyshell.restart_line(width, ''), expect)
+ self.assertEqual(pyshell.restart_line(taglen+2, ''), expect+' =')
+
+
 class PyShellFileListTest(unittest.TestCase):
 
 @classmethod
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index ea9465568bd9..08716a9733b7 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -387,6 +387,19 @@ def handle_EOF(self):
 "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 @@ def restart_subprocess(self, with_cwd=False, filename=''):
 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:
diff --git a/Misc/NEWS.d/next/IDLE/2019-09-05-23-12-13.bpo-38041.nxmGGK.rst b/Misc/NEWS.d/next/IDLE/2019-09-05-23-12-13.bpo-38041.nxmGGK.rst
new file mode 100644
index 000000000000..0aa254e8ca70
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2019-09-05-23-12-13.bpo-38041.nxmGGK.rst
@@ -0,0 +1,3 @@
+Shell restart lines now fill the window width, always start with '=',
+and avoid wrapping unnecessarily. The line will still wrap if the
+included file name is long relative to the width.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /