code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def completion_is_selected() -> bool: """ True when the user selected a completion. """ complete_state = get_app().current_buffer.complete_state return complete_state is not None and complete_state.current_completion is not None
True when the user selected a completion.
completion_is_selected
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def has_arg() -> bool: "Enable when the input processor has an 'arg'." return get_app().key_processor.arg is not None
Enable when the input processor has an 'arg'.
has_arg
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def in_editing_mode(editing_mode: EditingMode) -> Condition: """ Check whether a given editing mode is active. (Vi or Emacs.) """ @Condition def in_editing_mode_filter() -> bool: return get_app().editing_mode == editing_mode return in_editing_mode_filter
Check whether a given editing mode is active. (Vi or Emacs.)
in_editing_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def vi_navigation_mode() -> bool: """ Active when the set for Vi navigation key bindings are active. """ from prompt_toolkit.key_binding.vi_state import InputMode app = get_app() if ( app.editing_mode != EditingMode.VI or app.vi_state.operator_func or app.vi_state.waiti...
Active when the set for Vi navigation key bindings are active.
vi_navigation_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def emacs_mode() -> bool: "When the Emacs bindings are active." return get_app().editing_mode == EditingMode.EMACS
When the Emacs bindings are active.
emacs_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def control_is_searchable() -> bool: "When the current UIControl is searchable." from prompt_toolkit.layout.controls import BufferControl control = get_app().layout.current_control return ( isinstance(control, BufferControl) and control.search_buffer_control is not None )
When the current UIControl is searchable.
control_is_searchable
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/app.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/app.py
BSD-3-Clause
def __and__(self, other: Filter) -> Filter: """ Chaining of filters using the & operator. """ assert isinstance(other, Filter), f"Expecting filter, got {other!r}" if isinstance(other, Always): return self if isinstance(other, Never): return other ...
Chaining of filters using the & operator.
__and__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def __or__(self, other: Filter) -> Filter: """ Chaining of filters using the | operator. """ assert isinstance(other, Filter), f"Expecting filter, got {other!r}" if isinstance(other, Always): return other if isinstance(other, Never): return self ...
Chaining of filters using the | operator.
__or__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def __invert__(self) -> Filter: """ Inverting of filters using the ~ operator. """ if self._invert_result is None: self._invert_result = _Invert(self) return self._invert_result
Inverting of filters using the ~ operator.
__invert__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def __bool__(self) -> None: """ By purpose, we don't allow bool(...) operations directly on a filter, because the meaning is ambiguous. Executing a filter has to be done always by calling it. Providing defaults for `None` values should be done through an `is None` check ...
By purpose, we don't allow bool(...) operations directly on a filter, because the meaning is ambiguous. Executing a filter has to be done always by calling it. Providing defaults for `None` values should be done through an `is None` check instead of for instance ``filter1 or Al...
__bool__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def create(cls, filters: Iterable[Filter]) -> Filter: """ Create a new filter by applying an `&` operator between them. If there's only one unique filter in the given iterable, it will return that one filter instead of an `_AndList`. """ filters_2: list[Filter] = [] ...
Create a new filter by applying an `&` operator between them. If there's only one unique filter in the given iterable, it will return that one filter instead of an `_AndList`.
create
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def create(cls, filters: Iterable[Filter]) -> Filter: """ Create a new filter by applying an `|` operator between them. If there's only one unique filter in the given iterable, it will return that one filter instead of an `_OrList`. """ filters_2: list[Filter] = [] ...
Create a new filter by applying an `|` operator between them. If there's only one unique filter in the given iterable, it will return that one filter instead of an `_OrList`.
create
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/base.py
BSD-3-Clause
def to_filter(bool_or_filter: FilterOrBool) -> Filter: """ Accept both booleans and Filters as input and turn it into a Filter. """ if isinstance(bool_or_filter, bool): return _bool_to_filter[bool_or_filter] if isinstance(bool_or_filter, Filter): return bool_or_filter raise...
Accept both booleans and Filters as input and turn it into a Filter.
to_filter
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/filters/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/filters/utils.py
BSD-3-Clause
def _parse_corot(self) -> Generator[None, str, None]: """ Coroutine that parses the ANSI escape sequences. """ style = "" formatted_text = self._formatted_text while True: # NOTE: CSI is a special token within a stream of characters that # i...
Coroutine that parses the ANSI escape sequences.
_parse_corot
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/ansi.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/ansi.py
BSD-3-Clause
def _select_graphic_rendition(self, attrs: list[int]) -> None: """ Taken a list of graphics attributes and apply changes. """ if not attrs: attrs = [0] else: attrs = list(attrs[::-1]) while attrs: attr = attrs.pop() if att...
Taken a list of graphics attributes and apply changes.
_select_graphic_rendition
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/ansi.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/ansi.py
BSD-3-Clause
def _create_style_string(self) -> str: """ Turn current style flags into a string for usage in a formatted text. """ result = [] if self._color: result.append(self._color) if self._bgcolor: result.append("bg:" + self._bgcolor) if self._bold...
Turn current style flags into a string for usage in a formatted text.
_create_style_string
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/ansi.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/ansi.py
BSD-3-Clause
def to_formatted_text( value: AnyFormattedText, style: str = "", auto_convert: bool = False ) -> FormattedText: """ Convert the given value (which can be formatted text) into a list of text fragments. (Which is the canonical form of formatted text.) The outcome is always a `FormattedText` instance, ...
Convert the given value (which can be formatted text) into a list of text fragments. (Which is the canonical form of formatted text.) The outcome is always a `FormattedText` instance, which is a list of (style, text) tuples. It can take a plain text string, an `HTML` or `ANSI` object, anything that ...
to_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/base.py
BSD-3-Clause
def is_formatted_text(value: object) -> TypeGuard[AnyFormattedText]: """ Check whether the input is valid formatted text (for use in assert statements). In case of a callable, it doesn't check the return type. """ if callable(value): return True if isinstance(value, (str, list)): ...
Check whether the input is valid formatted text (for use in assert statements). In case of a callable, it doesn't check the return type.
is_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/base.py
BSD-3-Clause
def merge_formatted_text(items: Iterable[AnyFormattedText]) -> AnyFormattedText: """ Merge (Concatenate) several pieces of formatted text together. """ def _merge_formatted_text() -> AnyFormattedText: result = FormattedText() for i in items: result.extend(to_formatted_text(i...
Merge (Concatenate) several pieces of formatted text together.
merge_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/base.py
BSD-3-Clause
def get_current_style() -> str: "Build style string for current node." parts = [] if name_stack: parts.append("class:" + ",".join(name_stack)) if fg_stack: parts.append("fg:" + fg_stack[-1]) if bg_stack: parts.a...
Build style string for current node.
get_current_style
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/html.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/html.py
BSD-3-Clause
def fragment_list_len(fragments: StyleAndTextTuples) -> int: """ Return the amount of characters in this text fragment list. :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples. """ ZeroWidthEscape = "[ZeroWidthEscape]" return sum(len(item[1]) ...
Return the amount of characters in this text fragment list. :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples.
fragment_list_len
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/utils.py
BSD-3-Clause
def fragment_list_width(fragments: StyleAndTextTuples) -> int: """ Return the character width of this text fragment list. (Take double width characters into account.) :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples. """ ZeroWidthEscape = "[...
Return the character width of this text fragment list. (Take double width characters into account.) :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples.
fragment_list_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/utils.py
BSD-3-Clause
def fragment_list_to_text(fragments: StyleAndTextTuples) -> str: """ Concatenate all the text parts again. :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples. """ ZeroWidthEscape = "[ZeroWidthEscape]" return "".join(item[1] for item in fragmen...
Concatenate all the text parts again. :param fragments: List of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples.
fragment_list_to_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/utils.py
BSD-3-Clause
def split_lines( fragments: Iterable[OneStyleAndTextTuple], ) -> Iterable[StyleAndTextTuples]: """ Take a single list of (style_str, text) tuples and yield one such list for each line. Just like str.split, this will yield at least one item. :param fragments: Iterable of ``(style_str, text)`` or ...
Take a single list of (style_str, text) tuples and yield one such list for each line. Just like str.split, this will yield at least one item. :param fragments: Iterable of ``(style_str, text)`` or ``(style_str, text, mouse_handler)`` tuples.
split_lines
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/formatted_text/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/formatted_text/utils.py
BSD-3-Clause
def _get_reverse_ansi_sequences() -> dict[Keys, str]: """ Create a dictionary that maps prompt_toolkit keys back to the VT100 escape sequences. """ result: dict[Keys, str] = {} for sequence, key in ANSI_SEQUENCES.items(): if not isinstance(key, tuple): if key not in result: ...
Create a dictionary that maps prompt_toolkit keys back to the VT100 escape sequences.
_get_reverse_ansi_sequences
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/ansi_escape_sequences.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/ansi_escape_sequences.py
BSD-3-Clause
def fileno(self) -> int: """ Fileno for putting this in an event loop. """
Fileno for putting this in an event loop.
fileno
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def typeahead_hash(self) -> str: """ Identifier for storing type ahead key presses. """
Identifier for storing type ahead key presses.
typeahead_hash
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def read_keys(self) -> list[KeyPress]: """ Return a list of Key objects which are read/parsed from the input. """
Return a list of Key objects which are read/parsed from the input.
read_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def raw_mode(self) -> ContextManager[None]: """ Context manager that turns the input into raw mode. """
Context manager that turns the input into raw mode.
raw_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def cooked_mode(self) -> ContextManager[None]: """ Context manager that turns the input into cooked mode. """
Context manager that turns the input into cooked mode.
cooked_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def attach(self, input_ready_callback: Callable[[], None]) -> ContextManager[None]: """ Return a context manager that makes this input active in the current event loop. """
Return a context manager that makes this input active in the current event loop.
attach
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def detach(self) -> ContextManager[None]: """ Return a context manager that makes sure that this input is not active in the current event loop. """
Return a context manager that makes sure that this input is not active in the current event loop.
detach
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/base.py
BSD-3-Clause
def create_input(stdin: TextIO | None = None, always_prefer_tty: bool = False) -> Input: """ Create the appropriate `Input` object for the current os/environment. :param always_prefer_tty: When set, if `sys.stdin` is connected to a Unix `pipe`, check whether `sys.stdout` or `sys.stderr` are connect...
Create the appropriate `Input` object for the current os/environment. :param always_prefer_tty: When set, if `sys.stdin` is connected to a Unix `pipe`, check whether `sys.stdout` or `sys.stderr` are connected to a pseudo terminal. If so, open the tty for reading instead of reading for ...
create_input
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/defaults.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/defaults.py
BSD-3-Clause
def create_pipe_input() -> ContextManager[PipeInput]: """ Create an input pipe. This is mostly useful for unit testing. Usage:: with create_pipe_input() as input: input.send_text('inputdata') Breaking change: In prompt_toolkit 3.0.28 and earlier, this was returning the `Pi...
Create an input pipe. This is mostly useful for unit testing. Usage:: with create_pipe_input() as input: input.send_text('inputdata') Breaking change: In prompt_toolkit 3.0.28 and earlier, this was returning the `PipeInput` directly, rather than through a context manager. ...
create_pipe_input
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/defaults.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/defaults.py
BSD-3-Clause
def close_read(self) -> None: "Close read-end if not yet closed." if self._read_closed: return os.close(self.read_fd) self._read_closed = True
Close read-end if not yet closed.
close_read
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/posix_pipe.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/posix_pipe.py
BSD-3-Clause
def close_write(self) -> None: "Close write-end if not yet closed." if self._write_closed: return os.close(self.write_fd) self._write_closed = True
Close write-end if not yet closed.
close_write
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/posix_pipe.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/posix_pipe.py
BSD-3-Clause
def read(self, count: int = 1024) -> str: # By default we choose a rather small chunk size, because reading # big amounts of input at once, causes the event loop to process # all these key bindings also at once without going back to the # loop. This will make the application feel unrespo...
Read the input and return it as a string. Return the text. Note that this can return an empty string, even when the input stream was not yet closed. This means that something went wrong during the decoding.
read
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/posix_utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/posix_utils.py
BSD-3-Clause
def store_typeahead(input_obj: Input, key_presses: list[KeyPress]) -> None: """ Insert typeahead key presses for the given input. """ global _buffer key = input_obj.typeahead_hash() _buffer[key].extend(key_presses)
Insert typeahead key presses for the given input.
store_typeahead
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/typeahead.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/typeahead.py
BSD-3-Clause
def get_typeahead(input_obj: Input) -> list[KeyPress]: """ Retrieve typeahead and reset the buffer for this input. """ global _buffer key = input_obj.typeahead_hash() result = _buffer[key] _buffer[key] = [] return result
Retrieve typeahead and reset the buffer for this input.
get_typeahead
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/typeahead.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/typeahead.py
BSD-3-Clause
def flush_keys(self) -> list[KeyPress]: """ Flush pending keys and return them. (Used for flushing the 'escape' key.) """ # Flush all pending keys. (This is most important to flush the vt100 # 'Escape' key early when nothing else follows.) self.vt100_parser.flush(...
Flush pending keys and return them. (Used for flushing the 'escape' key.)
flush_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/vt100.py
BSD-3-Clause
def _attached_input( input: Vt100Input, callback: Callable[[], None] ) -> Generator[None, None, None]: """ Context manager that makes this input active in the current event loop. :param input: :class:`~prompt_toolkit.input.Input` object. :param callback: Called when the input is ready to read. ...
Context manager that makes this input active in the current event loop. :param input: :class:`~prompt_toolkit.input.Input` object. :param callback: Called when the input is ready to read.
_attached_input
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/vt100.py
BSD-3-Clause
def _get_match(self, prefix: str) -> None | Keys | tuple[Keys, ...]: """ Return the key (or keys) that maps to this prefix. """ # (hard coded) If we match a CPR response, return Keys.CPRResponse. # (This one doesn't fit in the ANSI_SEQUENCES, because it contains # integer...
Return the key (or keys) that maps to this prefix.
_get_match
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/vt100_parser.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/vt100_parser.py
BSD-3-Clause
def _input_parser_generator(self) -> Generator[None, str | _Flush, None]: """ Coroutine (state machine) for the input parser. """ prefix = "" retry = False flush = False while True: flush = False if retry: retry = False ...
Coroutine (state machine) for the input parser.
_input_parser_generator
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/vt100_parser.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/vt100_parser.py
BSD-3-Clause
def feed(self, data: str) -> None: """ Feed the input stream. :param data: Input string (unicode). """ # Handle bracketed paste. (We bypass the parser that matches all other # key presses and keep reading input until we see the end mark.) # This is much faster th...
Feed the input stream. :param data: Input string (unicode).
feed
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/vt100_parser.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/vt100_parser.py
BSD-3-Clause
def read(self) -> Iterable[KeyPress]: """ Return a list of `KeyPress` instances. It won't return anything when there was nothing to read. (This function doesn't block.) http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961(v=vs.85).aspx """ max_count = 2048 ...
Return a list of `KeyPress` instances. It won't return anything when there was nothing to read. (This function doesn't block.) http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961(v=vs.85).aspx
read
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _get_keys( self, read: DWORD, input_records: Array[INPUT_RECORD] ) -> Iterator[KeyPress]: """ Generator that yields `KeyPress` objects from the input records. """ for i in range(read.value): ir = input_records[i] # Get the right EventType from the...
Generator that yields `KeyPress` objects from the input records.
_get_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _merge_paired_surrogates(key_presses: list[KeyPress]) -> Iterator[KeyPress]: """ Combines consecutive KeyPresses with high and low surrogates into single characters """ buffered_high_surrogate = None for key in key_presses: is_text = not isinstance(key.key...
Combines consecutive KeyPresses with high and low surrogates into single characters
_merge_paired_surrogates
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _is_paste(keys: list[KeyPress]) -> bool: """ Return `True` when we should consider this list of keys as a paste event. Pasted text on windows will be turned into a `Keys.BracketedPaste` event. (It's not 100% correct, but it is probably the best possible way to detect pasting ...
Return `True` when we should consider this list of keys as a paste event. Pasted text on windows will be turned into a `Keys.BracketedPaste` event. (It's not 100% correct, but it is probably the best possible way to detect pasting of text and handle that correctly.)
_is_paste
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _event_to_key_presses(self, ev: KEY_EVENT_RECORD) -> list[KeyPress]: """ For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances. """ assert isinstance(ev, KEY_EVENT_RECORD) and ev.KeyDown result: KeyPress | None = None control_key_state = ev.ControlKeySt...
For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances.
_event_to_key_presses
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _handle_mouse(self, ev: MOUSE_EVENT_RECORD) -> list[KeyPress]: """ Handle mouse events. Return a list of KeyPress instances. """ event_flags = ev.EventFlags button_state = ev.ButtonState event_type: MouseEventType | None = None button: MouseButton = MouseButt...
Handle mouse events. Return a list of KeyPress instances.
_handle_mouse
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def add_win32_handle(self, handle: HANDLE, callback: Callable[[], None]) -> None: """ Add a Win32 handle to the event loop. """ handle_value = handle.value if handle_value is None: raise ValueError("Invalid handle.") # Make sure to remove a previous register...
Add a Win32 handle to the event loop.
add_win32_handle
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def remove_win32_handle(self, handle: HANDLE) -> Callable[[], None] | None: """ Remove a Win32 handle from the event loop. Return either the registered handler or `None`. """ if handle.value is None: return None # Ignore. # Trigger remove events, so that the...
Remove a Win32 handle from the event loop. Return either the registered handler or `None`.
remove_win32_handle
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def attach_win32_input( input: _Win32InputBase, callback: Callable[[], None] ) -> Iterator[None]: """ Context manager that makes this input active in the current event loop. :param input: :class:`~prompt_toolkit.input.Input` object. :param input_ready_callback: Called when the input is ready to rea...
Context manager that makes this input active in the current event loop. :param input: :class:`~prompt_toolkit.input.Input` object. :param input_ready_callback: Called when the input is ready to read.
attach_win32_input
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def _is_win_vt100_input_enabled() -> bool: """ Returns True when we're running Windows and VT100 escape sequences are supported. """ hconsole = HANDLE(windll.kernel32.GetStdHandle(STD_INPUT_HANDLE)) # Get original console mode. original_mode = DWORD(0) windll.kernel32.GetConsoleMode(hco...
Returns True when we're running Windows and VT100 escape sequences are supported.
_is_win_vt100_input_enabled
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32.py
BSD-3-Clause
def close(self) -> None: "Close write-end of the pipe." self._closed = True windll.kernel32.SetEvent(self._event)
Close write-end of the pipe.
close
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/input/win32_pipe.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/input/win32_pipe.py
BSD-3-Clause
def load_key_bindings() -> KeyBindingsBase: """ Create a KeyBindings object that contains the default key bindings. """ all_bindings = merge_key_bindings( [ # Load basic bindings. load_basic_bindings(), # Load emacs bindings. load_emacs_bindings(),...
Create a KeyBindings object that contains the default key bindings.
load_key_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/defaults.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/defaults.py
BSD-3-Clause
def is_recording(self) -> bool: "Tell whether we are recording a macro." return self.current_recording is not None
Tell whether we are recording a macro.
is_recording
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/emacs_state.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/emacs_state.py
BSD-3-Clause
def add( self, *keys: Keys | str, filter: FilterOrBool = True, eager: FilterOrBool = False, is_global: FilterOrBool = False, save_before: Callable[[KeyPressEvent], bool] = (lambda e: True), record_in_macro: FilterOrBool = True, ) -> Callable[[T], T]: "...
Decorator for adding a key bindings. :param filter: :class:`~prompt_toolkit.filters.Filter` to determine when this key binding is active. :param eager: :class:`~prompt_toolkit.filters.Filter` or `bool`. When True, ignore potential longer matches when this key binding is...
add
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def remove(self, *args: Keys | str | KeyHandlerCallable) -> None: """ Remove a key binding. This expects either a function that was given to `add` method as parameter or a sequence of key bindings. Raises `ValueError` when no bindings was found. Usage:: re...
Remove a key binding. This expects either a function that was given to `add` method as parameter or a sequence of key bindings. Raises `ValueError` when no bindings was found. Usage:: remove(handler) # Pass handler. remove('c-x', 'c-a') # Or pass th...
remove
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def get_bindings_for_keys(self, keys: KeysTuple) -> list[Binding]: """ Return a list of key bindings that can handle this key. (This return also inactive bindings, so the `filter` still has to be called, for checking it.) :param keys: tuple of keys. """ def get(...
Return a list of key bindings that can handle this key. (This return also inactive bindings, so the `filter` still has to be called, for checking it.) :param keys: tuple of keys.
get_bindings_for_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def get_bindings_starting_with_keys(self, keys: KeysTuple) -> list[Binding]: """ Return a list of key bindings that handle a key sequence starting with `keys`. (It does only return bindings for which the sequences are longer than `keys`. And like `get_bindings_for_keys`, it also includes...
Return a list of key bindings that handle a key sequence starting with `keys`. (It does only return bindings for which the sequences are longer than `keys`. And like `get_bindings_for_keys`, it also includes inactive bindings.) :param keys: tuple of keys.
get_bindings_starting_with_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def _parse_key(key: Keys | str) -> str | Keys: """ Replace key by alias and verify whether it's a valid one. """ # Already a parse key? -> Return it. if isinstance(key, Keys): return key # Lookup aliases. key = KEY_ALIASES.get(key, key) # Replace 'space' by ' ' if key == "s...
Replace key by alias and verify whether it's a valid one.
_parse_key
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def key_binding( filter: FilterOrBool = True, eager: FilterOrBool = False, is_global: FilterOrBool = False, save_before: Callable[[KeyPressEvent], bool] = (lambda event: True), record_in_macro: FilterOrBool = True, ) -> Callable[[KeyHandlerCallable], Binding]: """ Decorator that turn a funct...
Decorator that turn a function into a `Binding` object. This can be added to a `KeyBindings` object when a key binding is assigned.
key_binding
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def _update_cache(self) -> None: "If the original key bindings was changed. Update our copy version." expected_version = self.key_bindings._version if self._last_version != expected_version: bindings2 = KeyBindings() # Copy all bindings from `self.key_bindings`, adding ...
If the original key bindings was changed. Update our copy version.
_update_cache
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def _update_cache(self) -> None: """ If one of the original registries was changed. Update our merged version. """ expected_version = tuple(r._version for r in self.registries) if self._last_version != expected_version: bindings2 = KeyBindings() ...
If one of the original registries was changed. Update our merged version.
_update_cache
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_bindings.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_bindings.py
BSD-3-Clause
def _get_matches(self, key_presses: list[KeyPress]) -> list[Binding]: """ For a list of :class:`KeyPress` instances. Give the matching handlers that would handle this. """ keys = tuple(k.key for k in key_presses) # Try match, with mode flag return [b for b in sel...
For a list of :class:`KeyPress` instances. Give the matching handlers that would handle this.
_get_matches
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def _is_prefix_of_longer_match(self, key_presses: list[KeyPress]) -> bool: """ For a list of :class:`KeyPress` instances. Return True if there is any handler that is bound to a suffix of this keys. """ keys = tuple(k.key for k in key_presses) # Get the filters for all th...
For a list of :class:`KeyPress` instances. Return True if there is any handler that is bound to a suffix of this keys.
_is_prefix_of_longer_match
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def _process(self) -> Generator[None, KeyPress, None]: """ Coroutine implementing the key match algorithm. Key strokes are sent into this generator, and it calls the appropriate handlers. """ buffer = self.key_buffer retry = False while True: flush = ...
Coroutine implementing the key match algorithm. Key strokes are sent into this generator, and it calls the appropriate handlers.
_process
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def feed(self, key_press: KeyPress, first: bool = False) -> None: """ Add a new :class:`KeyPress` to the input queue. (Don't forget to call `process_keys` in order to process the queue.) :param first: If true, insert before everything else. """ if first: self...
Add a new :class:`KeyPress` to the input queue. (Don't forget to call `process_keys` in order to process the queue.) :param first: If true, insert before everything else.
feed
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def feed_multiple(self, key_presses: list[KeyPress], first: bool = False) -> None: """ :param first: If true, insert before everything else. """ if first: self.input_queue.extendleft(reversed(key_presses)) else: self.input_queue.extend(key_presses)
:param first: If true, insert before everything else.
feed_multiple
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def process_keys(self) -> None: """ Process all the keys in the `input_queue`. (To be called after `feed`.) Note: because of the `feed`/`process_keys` separation, it is possible to call `feed` from inside a key binding. This function keeps looping until the q...
Process all the keys in the `input_queue`. (To be called after `feed`.) Note: because of the `feed`/`process_keys` separation, it is possible to call `feed` from inside a key binding. This function keeps looping until the queue is empty.
process_keys
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def empty_queue(self) -> list[KeyPress]: """ Empty the input queue. Return the unprocessed input. """ key_presses = list(self.input_queue) self.input_queue.clear() # Filter out CPRs. We don't want to return these. key_presses = [k for k in key_presses if k.key !=...
Empty the input queue. Return the unprocessed input.
empty_queue
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def _fix_vi_cursor_position(self, event: KeyPressEvent) -> None: """ After every command, make sure that if we are in Vi navigation mode, we never put the cursor after the last character of a line. (Unless it's an empty line.) """ app = event.app buff = app.curren...
After every command, make sure that if we are in Vi navigation mode, we never put the cursor after the last character of a line. (Unless it's an empty line.)
_fix_vi_cursor_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def _leave_vi_temp_navigation_mode(self, event: KeyPressEvent) -> None: """ If we're in Vi temporary navigation (normal) mode, return to insert/replace mode after executing one action. """ app = event.app if app.editing_mode == EditingMode.VI: # Not waiting f...
If we're in Vi temporary navigation (normal) mode, return to insert/replace mode after executing one action.
_leave_vi_temp_navigation_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def _start_timeout(self) -> None: """ Start auto flush timeout. Similar to Vim's `timeoutlen` option. Start a background coroutine with a timer. When this timeout expires and no key was pressed in the meantime, we flush all data in the queue and call the appropriate key binding ...
Start auto flush timeout. Similar to Vim's `timeoutlen` option. Start a background coroutine with a timer. When this timeout expires and no key was pressed in the meantime, we flush all data in the queue and call the appropriate key binding handlers.
_start_timeout
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def append_to_arg_count(self, data: str) -> None: """ Add digit to the input argument. :param data: the typed digit as string """ assert data in "-0123456789" current = self._arg if data == "-": assert current is None or current == "-" re...
Add digit to the input argument. :param data: the typed digit as string
append_to_arg_count
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/key_processor.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/key_processor.py
BSD-3-Clause
def reset(self) -> None: """ Reset state, go back to the given mode. INSERT by default. """ # Go back to insert mode. self.input_mode = InputMode.INSERT self.waiting_for_digraph = False self.operator_func = None self.operator_arg = None # Reset r...
Reset state, go back to the given mode. INSERT by default.
reset
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/vi_state.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/vi_state.py
BSD-3-Clause
def load_auto_suggest_bindings() -> KeyBindings: """ Key bindings for accepting auto suggestion text. (This has to come after the Vi bindings, because they also have an implementation for the "right arrow", but we really want the suggestion binding when a suggestion is available.) """ key_b...
Key bindings for accepting auto suggestion text. (This has to come after the Vi bindings, because they also have an implementation for the "right arrow", but we really want the suggestion binding when a suggestion is available.)
load_auto_suggest_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/auto_suggest.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/auto_suggest.py
BSD-3-Clause
def generate_completions(event: E) -> None: r""" Tab-completion: where the first tab completes the common suffix and the second tab lists all the completions. """ b = event.current_buffer # When already navigating through completions, select the next one. if b.complete_state: b.comp...
Tab-completion: where the first tab completes the common suffix and the second tab lists all the completions.
generate_completions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/completion.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/completion.py
BSD-3-Clause
def display_completions_like_readline(event: E) -> None: """ Key binding handler for readline-style tab completion. This is meant to be as similar as possible to the way how readline displays completions. Generate the completions immediately (blocking) and display them above the prompt in colum...
Key binding handler for readline-style tab completion. This is meant to be as similar as possible to the way how readline displays completions. Generate the completions immediately (blocking) and display them above the prompt in columns. Usage:: # Call this handler when 'Tab' has bee...
display_completions_like_readline
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/completion.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/completion.py
BSD-3-Clause
def _display_completions_like_readline( app: Application[object], completions: list[Completion] ) -> asyncio.Task[None]: """ Display the list of completions in columns above the prompt. This will ask for a confirmation if there are too many completions to fit on a single page and provide a paginator...
Display the list of completions in columns above the prompt. This will ask for a confirmation if there are too many completions to fit on a single page and provide a paginator to walk through them.
_display_completions_like_readline
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/completion.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/completion.py
BSD-3-Clause
def _create_more_session(message: str = "--MORE--") -> PromptSession[bool]: """ Create a `PromptSession` object for displaying the "--MORE--". """ from prompt_toolkit.shortcuts import PromptSession bindings = KeyBindings() @bindings.add(" ") @bindings.add("y") @bindings.add("Y") @b...
Create a `PromptSession` object for displaying the "--MORE--".
_create_more_session
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/completion.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/completion.py
BSD-3-Clause
def _(event: E) -> None: """ Handle incoming Cursor-Position-Request response. """ # The incoming data looks like u'\x1b[35;1R' # Parse row/col information. row, col = map(int, event.data[2:-1].split(";")) # Report absolute cursor position to the renderer. ...
Handle incoming Cursor-Position-Request response.
_
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/cpr.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/cpr.py
BSD-3-Clause
def handle_digit(c: str) -> None: """ Handle input of arguments. The first number needs to be preceded by escape. """ @handle(c, filter=has_arg) @handle("escape", c) def _(event: E) -> None: event.append_to_arg_count(c)
Handle input of arguments. The first number needs to be preceded by escape.
handle_digit
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _goto_char(event: E) -> None: "When Ctl-] + a character is pressed. go to that character." # Also named 'character-search' character_search(event.current_buffer, event.data, event.arg)
When Ctl-] + a character is pressed. go to that character.
_goto_char
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _insert_all_completions(event: E) -> None: """ `meta-*`: Insert all possible completions of the preceding text. """ buff = event.current_buffer # List all completions. complete_event = CompleteEvent(text_inserted=False, completion_requested=True) completions ...
`meta-*`: Insert all possible completions of the preceding text.
_insert_all_completions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _toggle_start_end(event: E) -> None: """ Move cursor back and forth between the start and end of the current line. """ buffer = event.current_buffer if buffer.document.is_cursor_at_the_end_of_line: buffer.cursor_position += buffer.document.get_start_of_li...
Move cursor back and forth between the start and end of the current line.
_toggle_start_end
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _start_selection(event: E) -> None: """ Start of the selection (if the current buffer is not empty). """ # Take the current cursor position as the start of this selection. buff = event.current_buffer if buff.text: buff.start_selection(selection_type=Select...
Start of the selection (if the current buffer is not empty).
_start_selection
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _cancel(event: E) -> None: """ Control + G: Cancel completion menu and validation state. """ event.current_buffer.complete_state = None event.current_buffer.validation_error = None
Control + G: Cancel completion menu and validation state.
_cancel
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _start_of_word(event: E) -> None: """ Cursor to start of previous word. """ buffer = event.current_buffer buffer.cursor_position += ( buffer.document.find_previous_word_beginning(count=event.arg) or 0 )
Cursor to start of previous word.
_start_of_word
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _start_next_word(event: E) -> None: """ Cursor to start of next word. """ buffer = event.current_buffer buffer.cursor_position += ( buffer.document.find_next_word_beginning(count=event.arg) or buffer.document.get_end_of_document_position() )
Cursor to start of next word.
_start_next_word
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def load_emacs_shift_selection_bindings() -> KeyBindingsBase: """ Bindings to select text with shift + cursor movements """ key_bindings = KeyBindings() handle = key_bindings.add def unshift_move(event: E) -> None: """ Used for the shift selection mode. When called with ...
Bindings to select text with shift + cursor movements
load_emacs_shift_selection_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def unshift_move(event: E) -> None: """ Used for the shift selection mode. When called with a shift + movement key press event, moves the cursor as if shift is not pressed. """ key = event.key_sequence[0].key if key == Keys.ShiftUp: event.current_buff...
Used for the shift selection mode. When called with a shift + movement key press event, moves the cursor as if shift is not pressed.
unshift_move
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def _yank(event: E) -> None: """ In shift selection mode, yanking (pasting) replace the selection. """ buff = event.current_buffer if buff.selection_state: buff.cut_selection() get_by_name("yank").call(event)
In shift selection mode, yanking (pasting) replace the selection.
_yank
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/emacs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/emacs.py
BSD-3-Clause
def load_mouse_bindings() -> KeyBindings: """ Key bindings, required for mouse support. (Mouse events enter through the key binding system.) """ key_bindings = KeyBindings() @key_bindings.add(Keys.Vt100MouseEvent) def _(event: E) -> NotImplementedOrNone: """ Handling of inco...
Key bindings, required for mouse support. (Mouse events enter through the key binding system.)
load_mouse_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/mouse.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/mouse.py
BSD-3-Clause
def _scroll_up(event: E) -> None: """ Scroll up event without cursor position. """ # We don't receive a cursor position, so we don't know which window to # scroll. Just send an 'up' key press instead. event.key_processor.feed(KeyPress(Keys.Up), first=True)
Scroll up event without cursor position.
_scroll_up
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/mouse.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/mouse.py
BSD-3-Clause
def _mouse(event: E) -> NotImplementedOrNone: """ Handling of mouse events for Windows. """ # This key binding should only exist for Windows. if sys.platform == "win32": # Parse data. pieces = event.data.split(";") button = MouseButton(pieces[...
Handling of mouse events for Windows.
_mouse
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/mouse.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/mouse.py
BSD-3-Clause
def get_by_name(name: str) -> Binding: """ Return the handler for the (Readline) command with the given name. """ try: return _readline_commands[name] except KeyError as e: raise KeyError(f"Unknown Readline command: {name!r}") from e
Return the handler for the (Readline) command with the given name.
get_by_name
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/named_commands.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/named_commands.py
BSD-3-Clause
def beginning_of_buffer(event: E) -> None: """ Move to the start of the buffer. """ buff = event.current_buffer buff.cursor_position = 0
Move to the start of the buffer.
beginning_of_buffer
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/named_commands.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/named_commands.py
BSD-3-Clause
def end_of_buffer(event: E) -> None: """ Move to the end of the buffer. """ buff = event.current_buffer buff.cursor_position = len(buff.text)
Move to the end of the buffer.
end_of_buffer
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/key_binding/bindings/named_commands.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/key_binding/bindings/named_commands.py
BSD-3-Clause