[3.13] gh-119034, REPL: Change page up/down keys to search in history (GH-123607) (GH-123773)

Change <page up> and <page down> keys of the Python REPL to history
search forward/backward.

(cherry picked from commit 8311b11800)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2024-09-06 14:04:11 +02:00 committed by GitHub
parent b221c5bba1
commit c787a5161c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 113 additions and 4 deletions

View file

@ -676,6 +676,45 @@ def test_control_character(self):
self.assertEqual(output, "c\x1d")
self.assertEqual(clean_screen(reader.screen), "c")
def test_history_search_backward(self):
# Test <page up> history search backward with "imp" input
events = itertools.chain(
code_to_events("import os\n"),
code_to_events("imp"),
[
Event(evt='key', data='page up', raw=bytearray(b'\x1b[5~')),
Event(evt="key", data="\n", raw=bytearray(b"\n")),
],
)
# fill the history
reader = self.prepare_reader(events)
multiline_input(reader)
# search for "imp" in history
output = multiline_input(reader)
self.assertEqual(output, "import os")
self.assertEqual(clean_screen(reader.screen), "import os")
def test_history_search_backward_empty(self):
# Test <page up> history search backward with an empty input
events = itertools.chain(
code_to_events("import os\n"),
[
Event(evt='key', data='page up', raw=bytearray(b'\x1b[5~')),
Event(evt="key", data="\n", raw=bytearray(b"\n")),
],
)
# fill the history
reader = self.prepare_reader(events)
multiline_input(reader)
# search backward in history
output = multiline_input(reader)
self.assertEqual(output, "import os")
self.assertEqual(clean_screen(reader.screen), "import os")
class TestPyReplCompleter(TestCase):
def prepare_reader(self, events, namespace):