mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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:
parent
d683f49a7b
commit
8311b11800
5 changed files with 113 additions and 4 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue