Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-38041: Refine IDLE Shell restart lines. #15709

Merged
merged 11 commits into from
Sep 6, 2019
4 changes: 4 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Released on 2019-10-20?
======================================


bpo-38401: Shell restart lines now fill the window width and always
terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
start with '='. Filenames still wrap if long relative to the width,
but there is no longer a trailing space that can wrap by itself.

bpo-37092: Add mousewheel scrolling for IDLE module, path, and stack
browsers. Patch by George Zhang.

Expand Down
22 changes: 22 additions & 0 deletions Lib/idlelib/idle_test/test_pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 if file else 'Shell'
terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
line = pyshell.restart_line(width, file)
eq(len(line), width + 1) # +1 for '\n'
eq(line, f"\n{bar+extra} RESTART: {file} {bar}")

def test_restart_line_narrow(self):
expect, taglen = "\n= RESTART: Shell", 16 # Don't count '\n'.
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
Expand Down
14 changes: 11 additions & 3 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ def handle_EOF(self):
"Override the base class - just re-raise EOFError"
raise EOFError

def restart_line(width, filename): # See bpo-38141.
terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
if filename == '':
filename = 'Shell'
tag = f"= RESTART: {filename} ="
if width >= 13 + len(filename): # The length of tag.
terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
div, mod = divmod((width -len(tag)), 2)
return f"\n{(div+mod)*'='}{tag}{div*'='}"
terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
else:
return '\n' + tag[:-2] # Remove ' ='.


class ModifiedInterpreter(InteractiveInterpreter):

Expand Down Expand Up @@ -491,9 +501,7 @@ 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(restart_line(console.width, filename))
console.text.mark_set("restart", "end-1c")
console.text.mark_gravity("restart", "left")
if not filename:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IDLE Shell restart lines now fill the window width and always start with
'='. Filenames still wrap if long relative to the width, but there is
no longer a trailing space that can wrap by itself.