Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-118878: Pyrepl: show completions menu below the current line #118939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
danielhollas committed May 22, 2024
commit 4498c2915721b175a172f52b65b1490c5918235b
9 changes: 5 additions & 4 deletions 9 Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ def after_command(self, cmd: Command) -> None:
def calc_complete_screen(self) -> list[str]:
screen = super().calc_complete_screen()
if self.cmpltn_menu_visible:
# We display the completions menu below the current prompt
ly = self.lxy[1] + 1
pablogsal marked this conversation as resolved.
Show resolved Hide resolved
screen[ly:ly] = self.cmpltn_menu
# This is a horrible hack. If we're not in the middle
# of multiline edit, don't append to screeninfo
# since that screws up the position calculation
# in pos2xy function.
# If we're not in the middle of multiline edit, don't append to screeninfo
# since that screws up the position calculation in pos2xy function.
# This is a hack to prevent the cursor jumping
# into the completions menu when pressing left or down arrow.
if self.pos != len(self.buffer):
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
return screen
Expand Down
26 changes: 25 additions & 1 deletion 26 Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def test_global_namespace_completion(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "python")

def test_updown_arrow_with_completion_menu(self):
def test_up_down_arrow_with_completion_menu(self):
"""Up arrow in the middle of unfinished tab completion when the menu is displayed
should work and trigger going back in history. Down arrow should subsequently
get us back to the incomplete command."""
Expand All @@ -571,6 +571,30 @@ def test_updown_arrow_with_completion_menu(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "os.")

# TODO: This test doesn't seem to work as intended, it always succeeds
def test_right_down_arrows_with_completion_menu(self):
"""Right / Down arrows while the tab completion menu is displayed
should do nothing"""
code = "os.\t\t"
namespace = {"os": os}

events = itertools.chain(
code_to_events(code),
[
Event(evt="key", data="down", raw=bytearray(b"\x1bOB")),
Event(evt="key", data="right", raw=bytearray(b"\x1bOC")),
],
code_to_events("\n")
)
reader = self.prepare_reader(events, namespace=namespace)
output = multiline_input(reader, namespace)
self.assertEqual(output, "os.")
# When we press right and/or down arrow while
# the completions menu is displayed,
# the cursor should stay where it was on the line.
self.assertEqual(reader.cmpltn_menu_vis, 1)
self.assertEqual(reader.cxy, (6, 0))

@patch("_pyrepl.readline._ReadlineWrapper.get_reader")
@patch("sys.stderr", new_callable=io.StringIO)
def test_completion_with_warnings(self, mock_stderr, mock_get_reader):
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.