gh-119034, REPL: Change page up/down keys to search in history (#123607)

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

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Victor Stinner 2024-09-06 13:15:00 +02:00 committed by GitHub
parent d683f49a7b
commit 8311b11800
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 @@ class TestPyReplOutput(TestCase):
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):