Skip to content
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

Adding pattern to NestedCompleter. #1752

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
12 changes: 9 additions & 3 deletions src/prompt_toolkit/completion/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Any, Iterable, Mapping, Set, Union
from typing import Any, Iterable, Mapping, Pattern, Set, Union

from prompt_toolkit.completion import CompleteEvent, Completer, Completion
from prompt_toolkit.completion.word_completer import WordCompleter
Expand All @@ -28,10 +28,14 @@ class NestedCompleter(Completer):
"""

def __init__(
self, options: dict[str, Completer | None], ignore_case: bool = True
self,
options: dict[str, Completer | None],
ignore_case: bool = True,
pattern: Pattern[str] | None = None,
) -> None:
self.options = options
self.ignore_case = ignore_case
self.pattern = pattern

def __repr__(self) -> str:
return f"NestedCompleter({self.options!r}, ignore_case={self.ignore_case!r})"
Expand Down Expand Up @@ -103,6 +107,8 @@ def get_completions(
# No space in the input: behave exactly like `WordCompleter`.
else:
completer = WordCompleter(
list(self.options.keys()), ignore_case=self.ignore_case
list(self.options.keys()),
ignore_case=self.ignore_case,
pattern=self.pattern,
)
yield from completer.get_completions(document, complete_event)