mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[3.13] gh-119553: Clear reader on Ctrl-C command (GH-119801) (#120062)
(cherry picked from commit 010ea93b2b
)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
fd5428d2d1
commit
93b95e91fa
3 changed files with 19 additions and 0 deletions
|
@ -221,6 +221,7 @@ class interrupt(FinishCommand):
|
|||
|
||||
class ctrl_c(Command):
|
||||
def do(self) -> None:
|
||||
self.reader.finish()
|
||||
raise KeyboardInterrupt
|
||||
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ def handle_all_events(
|
|||
reader.handle1()
|
||||
except StopIteration:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
return reader, console
|
||||
|
||||
|
||||
|
|
|
@ -179,6 +179,22 @@ class TestReader(TestCase):
|
|||
self.assert_screen_equals(reader, expected)
|
||||
self.assertTrue(reader.finished)
|
||||
|
||||
def test_keyboard_interrupt_clears_screen(self):
|
||||
namespace = {"itertools": itertools}
|
||||
code = "import itertools\nitertools."
|
||||
events = itertools.chain(code_to_events(code), [
|
||||
Event(evt='key', data='\t', raw=bytearray(b'\t')), # Two tabs for completion
|
||||
Event(evt='key', data='\t', raw=bytearray(b'\t')),
|
||||
Event(evt='key', data='\x03', raw=bytearray(b'\x03')), # Ctrl-C
|
||||
])
|
||||
|
||||
completing_reader = functools.partial(
|
||||
prepare_reader,
|
||||
readline_completer=rlcompleter.Completer(namespace).complete
|
||||
)
|
||||
reader, _ = handle_all_events(events, prepare_reader=completing_reader)
|
||||
self.assertEqual(reader.calc_screen(), code.split("\n"))
|
||||
|
||||
def test_prompt_length(self):
|
||||
# Handles simple ASCII prompt
|
||||
ps1 = ">>> "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue