euporie.core.widgets.inputs.Buffer
- class euporie.core.widgets.inputs.Buffer(completer: prompt_toolkit.completion.base.Completer | None = None, auto_suggest: prompt_toolkit.auto_suggest.AutoSuggest | None = None, history: prompt_toolkit.history.History | None = None, validator: prompt_toolkit.validation.Validator | None = None, tempfile_suffix: Union[str, Callable[[], str]] = '', tempfile: Union[str, Callable[[], str]] = '', name: str = '', complete_while_typing: Union[Filter, bool] = False, validate_while_typing: Union[Filter, bool] = False, enable_history_search: Union[Filter, bool] = False, document: prompt_toolkit.document.Document | None = None, accept_handler: Optional[Callable[[Buffer], bool]] = None, read_only: Union[Filter, bool] = False, multiline: Union[Filter, bool] = True, max_number_of_completions: int = 10000, on_text_changed: Optional[Callable[[Buffer], None]] = None, on_text_insert: Optional[Callable[[Buffer], None]] = None, on_cursor_position_changed: Optional[Callable[[Buffer], None]] = None, on_completions_changed: Optional[Callable[[Buffer], None]] = None, on_suggestion_set: Optional[Callable[[Buffer], None]] = None)
The core data structure that holds the text and cursor position of the current input line and implements all text manipulations on top of it. It also implements the history, undo stack and the completion state.
- Parameters:
completer –
Completer
instance.history –
History
instance.tempfile_suffix – The tempfile suffix (extension) to be used for the “open in editor” function. For a Python REPL, this would be “.py”, so that the editor knows the syntax highlighting to use. This can also be a callable that returns a string.
tempfile – For more advanced tempfile situations where you need control over the subdirectories and filename. For a Git Commit Message, this would be “.git/COMMIT_EDITMSG”, so that the editor knows the syntax highlighting to use. This can also be a callable that returns a string.
name – Name for this buffer. E.g. DEFAULT_BUFFER. This is mostly useful for key bindings where we sometimes prefer to refer to a buffer by their name instead of by reference.
accept_handler –
Called when the buffer input is accepted. (Usually when the user presses enter.) The accept handler receives this Buffer as input and should return True when the buffer text should be kept instead of calling reset.
In case of a PromptSession for instance, we want to keep the text, because we will exit the application, and only reset it during the next run.
max_number_of_completions – Never display more than this number of completions, even when the completer can produce more (limited by default to 10k for performance).
Events:
- Parameters:
on_text_changed – When the buffer text changes. (Callable or None.)
on_text_insert – When new text is inserted. (Callable or None.)
on_cursor_position_changed – When the cursor moves. (Callable or None.)
on_completions_changed – When the completions were changed. (Callable or None.)
on_suggestion_set – When an auto-suggestion text has been set. (Callable or None.)
Filters:
- Parameters:
complete_while_typing –
Filter
or bool. Decide whether or not to do asynchronous autocompleting while typing.validate_while_typing –
Filter
or bool. Decide whether or not to do asynchronous validation while typing.enable_history_search –
Filter
or bool to indicate when up-arrow partial string matching is enabled. It is advised to not enable this at the same time as complete_while_typing, because when there is an autocompletion found, the up arrows usually browse through the completions, rather than through the history.read_only –
Filter
. When True, changes will not be allowed.multiline –
Filter
or bool. When not set, pressing Enter will call the accept_handler. Otherwise, pressing Esc-Enter is required.