prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Always display first completion

Open
#891 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

With prompt_toolkit 1 it was possible to return multiple completions and always first completion was selected. After update to PT2, this isn't possible. When I try to complete with TAB key, only partial completion is used (only "msg" string) and second TAB should be pressed to full completion. Can I somehow emulate PT1 behaviour? Here is my example code:

from prompt_toolkit import prompt
from prompt_toolkit.completion import Completer, Completion

class MyCustomCompleter(Completer):
    def get_completions(self, document, complete_event):
        yield Completion('msg test', start_position=0)
        yield Completion('msg help', start_position=0)

text1 = prompt(">> ",
  completer=MyCustomCompleter(),
  complete_while_typing=True,
  reserve_space_for_menu=0
)
print("RESULT:", repr(text1))

I need after first TAB to see "msg test" in prompt.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MyCustomCompleter.get_completions example and the prompt call using prompt_toolkit 2. Run it and inspect how the first TAB handles the two yielded Completion objects. Done means the first TAB inserts the full "msg test" completion, matching the reported prompt_toolkit 1 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.