Skip to content

Commit 7b3041a

Browse files
committed
Add ability to change the autosuggestion class.
Mostly up for discussion;but while working with multiline completion and LLM, I realised that in IPython it is likely Ii also want to handle suggestion when on the last line, so I think i'd like to ed the autocompltion class to a no-op one. Ideally I think it woudl make sens to completly control the full conditional processor; so mostly openeing that for discussion.
1 parent c6ce1a5 commit 7b3041a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/prompt_toolkit/shortcuts/prompt.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ class PromptSession(Generic[_T]):
328328
there is a keyboard interrupt (control-c keypress).
329329
:param eof_exception: The exception type that will be raised when there is
330330
an end-of-file/exit event (control-d keypress).
331+
:param append_autosuggestion_class: The class of the `Processor` that will
332+
be used to append autosuggestions to the current buffer. Default to
333+
`AppendAutoSuggestion`, that can only handle single line suggestions to
334+
the last line of the current buffer
331335
"""
332336

333337
_fields = (
@@ -416,6 +420,7 @@ def __init__(
416420
output: Output | None = None,
417421
interrupt_exception: type[BaseException] = KeyboardInterrupt,
418422
eof_exception: type[BaseException] = EOFError,
423+
append_autosuggestion_class=AppendAutoSuggestion,
419424
) -> None:
420425
history = history or InMemoryHistory()
421426
clipboard = clipboard or InMemoryClipboard()
@@ -472,7 +477,9 @@ def __init__(
472477
self.history = history
473478
self.default_buffer = self._create_default_buffer()
474479
self.search_buffer = self._create_search_buffer()
475-
self.layout = self._create_layout()
480+
self.layout = self._create_layout(
481+
append_autosuggestion_class=append_autosuggestion_class
482+
)
476483
self.app = self._create_application(editing_mode, erase_when_done)
477484

478485
def _dyncond(self, attr_name: str) -> Condition:
@@ -533,7 +540,7 @@ def accept(buff: Buffer) -> bool:
533540
def _create_search_buffer(self) -> Buffer:
534541
return Buffer(name=SEARCH_BUFFER)
535542

536-
def _create_layout(self) -> Layout:
543+
def _create_layout(self, append_autosuggestion_class) -> Layout:
537544
"""
538545
Create `Layout` for this prompt.
539546
"""
@@ -559,7 +566,7 @@ def display_placeholder() -> bool:
559566
HighlightIncrementalSearchProcessor(),
560567
HighlightSelectionProcessor(),
561568
ConditionalProcessor(
562-
AppendAutoSuggestion(), has_focus(default_buffer) & ~is_done
569+
append_autosuggestion_class(), has_focus(default_buffer) & ~is_done
563570
),
564571
ConditionalProcessor(PasswordProcessor(), dyncond("is_password")),
565572
DisplayMultipleCursors(),

0 commit comments

Comments
 (0)