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

Add ability to change the autosuggestion class. #1966

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
13 changes: 10 additions & 3 deletions src/prompt_toolkit/shortcuts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ class PromptSession(Generic[_T]):
there is a keyboard interrupt (control-c keypress).
:param eof_exception: The exception type that will be raised when there is
an end-of-file/exit event (control-d keypress).
:param append_autosuggestion_class: The class of the `Processor` that will
be used to append autosuggestions to the current buffer. Default to
`AppendAutoSuggestion`, that can only handle single line suggestions to
the last line of the current buffer
"""

_fields = (
Expand Down Expand Up @@ -416,6 +420,7 @@ def __init__(
output: Output | None = None,
interrupt_exception: type[BaseException] = KeyboardInterrupt,
eof_exception: type[BaseException] = EOFError,
append_autosuggestion_class=AppendAutoSuggestion,
) -> None:
history = history or InMemoryHistory()
clipboard = clipboard or InMemoryClipboard()
Expand Down Expand Up @@ -472,7 +477,9 @@ def __init__(
self.history = history
self.default_buffer = self._create_default_buffer()
self.search_buffer = self._create_search_buffer()
self.layout = self._create_layout()
self.layout = self._create_layout(
append_autosuggestion_class=append_autosuggestion_class
)
self.app = self._create_application(editing_mode, erase_when_done)

def _dyncond(self, attr_name: str) -> Condition:
Expand Down Expand Up @@ -533,7 +540,7 @@ def accept(buff: Buffer) -> bool:
def _create_search_buffer(self) -> Buffer:
return Buffer(name=SEARCH_BUFFER)

def _create_layout(self) -> Layout:
def _create_layout(self, append_autosuggestion_class) -> Layout:
"""
Create `Layout` for this prompt.
"""
Expand All @@ -559,7 +566,7 @@ def display_placeholder() -> bool:
HighlightIncrementalSearchProcessor(),
HighlightSelectionProcessor(),
ConditionalProcessor(
AppendAutoSuggestion(), has_focus(default_buffer) & ~is_done
append_autosuggestion_class(), has_focus(default_buffer) & ~is_done
),
ConditionalProcessor(PasswordProcessor(), dyncond("is_password")),
DisplayMultipleCursors(),
Expand Down
Loading