Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Lib/idlelib/idle_test/test_pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,42 @@ def test_output_at_prompt(self):
self.assertEqual(shell.shell_sidebar.line_prompts, {3: '>>>'})


class InputStatementlTest(unittest.TestCase):
Comment thread
terryjreedy marked this conversation as resolved.
# Test handling of response to input statements in user code.

@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
cls.shell = pyshell.PyShell(pyshell.PyShellFileList(cls.root))
# As after begin().
cls.shell.text.mark_set('iomark', 'insert')
cls.shell.text.mark_gravity('iomark', 'left')

@classmethod
def tearDownClass(cls):
cls.shell.close()
del cls.shell
cls.root.destroy()
del cls.root

def test_input_not_colorized(self):
# gh-64007: input for input() is not colorized, unlike code.
shell = self.shell
text = shell.text
color = shell.color
shell.resetoutput()
color.reading = True
text.insert('end-1c', 'for x in y')
color.recolorize_main()
self.assertEqual(text.tag_ranges('KEYWORD'), ())
color.reading = False
color.notify_range('iomark', 'end')
color.recolorize_main()
self.assertEqual(len(text.tag_ranges('KEYWORD')), 4)
Comment thread
terryjreedy marked this conversation as resolved.


class PyShellRemoveLastNewlineAndSurroundingWhitespaceTest(unittest.TestCase):
regexp = pyshell.PyShell._last_newline_re

Expand Down
12 changes: 10 additions & 2 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,13 @@ def open_shell(self, event=None):

class ModifiedColorDelegator(ColorDelegator):
"Extend base class: colorizer for the shell window itself"
reading = False # True while the user enters input for input().

def recolorize_main(self):
self.tag_remove("TODO", "1.0", "iomark")
self.tag_add("SYNC", "1.0", "iomark")
# Do not colorize output, nor input for input() (gh-64007).
end = "end" if self.reading else "iomark"
self.tag_remove("TODO", "1.0", end)
self.tag_add("SYNC", "1.0", end)
ColorDelegator.recolorize_main(self)

def removecolors(self):
Expand Down Expand Up @@ -1189,9 +1193,13 @@ def readline(self):
save = self.reading
try:
self.reading = True
# Input is not Python code (gh-64007).
self.color.reading = True
self.color.removecolors()
self.top.mainloop() # nested mainloop()
finally:
self.reading = save
self.color.reading = save
if self._stop_readline_flag:
self._stop_readline_flag = False
return ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IDLE no longer applies syntax coloring to the text entered for
:func:`input` in the Shell.
Loading