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 start_search(
buffer_control: BufferControl | None = None,
direction: SearchDirection = SearchDirection.FORWARD,
) -> None:
"""
Start search through the given `buffer_control` using the
`search_buffer_control`.
:param buffer_control: Start search for this `BufferControl`. If not given,
... |
Start search through the given `buffer_control` using the
`search_buffer_control`.
:param buffer_control: Start search for this `BufferControl`. If not given,
search through the current control.
| start_search | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/search.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/search.py | BSD-3-Clause |
def do_incremental_search(direction: SearchDirection, count: int = 1) -> None:
"""
Apply search, but keep search buffer focused.
"""
assert is_searching()
layout = get_app().layout
# Only search if the current control is a `BufferControl`.
from prompt_toolkit.layout.controls import BufferC... |
Apply search, but keep search buffer focused.
| do_incremental_search | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/search.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/search.py | BSD-3-Clause |
def accept_search() -> None:
"""
Accept current search query. Focus original `BufferControl` again.
"""
layout = get_app().layout
search_control = layout.current_control
target_buffer_control = layout.search_target_buffer_control
from prompt_toolkit.layout.controls import BufferControl
... |
Accept current search query. Focus original `BufferControl` again.
| accept_search | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/search.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/search.py | BSD-3-Clause |
def _get_reverse_search_links(
layout: Layout,
) -> dict[BufferControl, SearchBufferControl]:
"""
Return mapping from BufferControl to SearchBufferControl.
"""
return {
buffer_control: search_buffer_control
for search_buffer_control, buffer_control in layout.search_links.items()
... |
Return mapping from BufferControl to SearchBufferControl.
| _get_reverse_search_links | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/search.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/search.py | BSD-3-Clause |
def is_windows_vt100_supported() -> bool:
"""
True when we are using Windows, but VT100 escape sequences are supported.
"""
if sys.platform == "win32":
# Import needs to be inline. Windows libraries are not always available.
from prompt_toolkit.output.windows10 import is_win_vt100_enable... |
True when we are using Windows, but VT100 escape sequences are supported.
| is_windows_vt100_supported | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def get_bell_environment_variable() -> bool:
"""
True if env variable is set to true (true, TRUE, True, 1).
"""
value = os.environ.get("PROMPT_TOOLKIT_BELL", "true")
return value.lower() in ("1", "true") |
True if env variable is set to true (true, TRUE, True, 1).
| get_bell_environment_variable | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def take_using_weights(
items: list[_T], weights: list[int]
) -> Generator[_T, None, None]:
"""
Generator that keeps yielding items from the items list, in proportion to
their weight. For instance::
# Getting the first 70 items from this generator should have yielded 10
# times A, 20 ti... |
Generator that keeps yielding items from the items list, in proportion to
their weight. For instance::
# Getting the first 70 items from this generator should have yielded 10
# times A, 20 times B and 40 times C, all distributed equally..
take_using_weights(['A', 'B', 'C'], [5, 10, 20]... | take_using_weights | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def to_str(value: Callable[[], str] | str) -> str:
"Turn callable or string into string."
if callable(value):
return to_str(value())
else:
return str(value) | Turn callable or string into string. | to_str | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def to_int(value: Callable[[], int] | int) -> int:
"Turn callable or int into int."
if callable(value):
return to_int(value())
else:
return int(value) | Turn callable or int into int. | to_int | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def to_float(value: AnyFloat) -> float:
"Turn callable or float into float."
if callable(value):
return to_float(value())
else:
return float(value) | Turn callable or float into float. | to_float | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
def is_dumb_terminal(term: str | None = None) -> bool:
"""
True if this terminal type is considered "dumb".
If so, we should fall back to the simplest possible form of line editing,
without cursor positioning and color support.
"""
if term is None:
return is_dumb_terminal(os.environ.get... |
True if this terminal type is considered "dumb".
If so, we should fall back to the simplest possible form of line editing,
without cursor positioning and color support.
| is_dumb_terminal | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/utils.py | BSD-3-Clause |
async def validate_async(self, document: Document) -> None:
"""
Return a `Future` which is set when the validation is ready.
This function can be overloaded in order to provide an asynchronous
implementation.
"""
try:
self.validate(document)
except Val... |
Return a `Future` which is set when the validation is ready.
This function can be overloaded in order to provide an asynchronous
implementation.
| validate_async | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/validation.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/validation.py | BSD-3-Clause |
def from_callable(
cls,
validate_func: Callable[[str], bool],
error_message: str = "Invalid input",
move_cursor_to_end: bool = False,
) -> Validator:
"""
Create a validator from a simple validate callable. E.g.:
.. code:: python
def is_valid(text... |
Create a validator from a simple validate callable. E.g.:
.. code:: python
def is_valid(text):
return text in ['hello', 'world']
Validator.from_callable(is_valid, error_message='Invalid input')
:param validate_func: Callable that takes the input string... | from_callable | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/validation.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/validation.py | BSD-3-Clause |
async def validate_async(self, document: Document) -> None:
"""
Run the `validate` function in a thread.
"""
def run_validation_thread() -> None:
return self.validate(document)
await run_in_executor_with_context(run_validation_thread) |
Run the `validate` function in a thread.
| validate_async | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/validation.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/validation.py | BSD-3-Clause |
def _create_merged_style(self, include_default_pygments_style: Filter) -> BaseStyle:
"""
Create a `Style` object that merges the default UI style, the default
pygments style, and the custom user style.
"""
dummy_style = DummyStyle()
pygments_style = default_pygments_style... |
Create a `Style` object that merges the default UI style, the default
pygments style, and the custom user style.
| _create_merged_style | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def color_depth(self) -> ColorDepth:
"""
The active :class:`.ColorDepth`.
The current value is determined as follows:
- If a color depth was given explicitly to this application, use that
value.
- Otherwise, fall back to the color depth that is reported by the
... |
The active :class:`.ColorDepth`.
The current value is determined as follows:
- If a color depth was given explicitly to this application, use that
value.
- Otherwise, fall back to the color depth that is reported by the
:class:`.Output` implementation. If the :clas... | color_depth | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def current_buffer(self) -> Buffer:
"""
The currently focused :class:`~.Buffer`.
(This returns a dummy :class:`.Buffer` when none of the actual buffers
has the focus. In this case, it's really not practical to check for
`None` values or catch exceptions every time.)
"""
... |
The currently focused :class:`~.Buffer`.
(This returns a dummy :class:`.Buffer` when none of the actual buffers
has the focus. In this case, it's really not practical to check for
`None` values or catch exceptions every time.)
| current_buffer | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def current_search_state(self) -> SearchState:
"""
Return the current :class:`.SearchState`. (The one for the focused
:class:`.BufferControl`.)
"""
ui_control = self.layout.current_control
if isinstance(ui_control, BufferControl):
return ui_control.search_stat... |
Return the current :class:`.SearchState`. (The one for the focused
:class:`.BufferControl`.)
| current_search_state | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def reset(self) -> None:
"""
Reset everything, for reading the next input.
"""
# Notice that we don't reset the buffers. (This happens just before
# returning, and when we have multiple buffers, we clearly want the
# content in the other buffers to remain unchanged betwee... |
Reset everything, for reading the next input.
| reset | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def invalidate(self) -> None:
"""
Thread safe way of sending a repaint trigger to the input event loop.
"""
if not self._is_running:
# Don't schedule a redraw if we're not running.
# Otherwise, `get_running_loop()` in `call_soon_threadsafe` can fail.
#... |
Thread safe way of sending a repaint trigger to the input event loop.
| invalidate | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _redraw(self, render_as_done: bool = False) -> None:
"""
Render the command line again. (Not thread safe!) (From other threads,
or if unsure, use :meth:`.Application.invalidate`.)
:param render_as_done: make sure to put the cursor after the UI.
"""
def run_in_contex... |
Render the command line again. (Not thread safe!) (From other threads,
or if unsure, use :meth:`.Application.invalidate`.)
:param render_as_done: make sure to put the cursor after the UI.
| _redraw | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _start_auto_refresh_task(self) -> None:
"""
Start a while/true loop in the background for automatic invalidation of
the UI.
"""
if self.refresh_interval is not None and self.refresh_interval != 0:
async def auto_refresh(refresh_interval: float) -> None:
... |
Start a while/true loop in the background for automatic invalidation of
the UI.
| _start_auto_refresh_task | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _update_invalidate_events(self) -> None:
"""
Make sure to attach 'invalidate' handlers to all invalidate events in
the UI.
"""
# Remove all the original event handlers. (Components can be removed
# from the UI.)
for ev in self._invalidate_events:
e... |
Make sure to attach 'invalidate' handlers to all invalidate events in
the UI.
| _update_invalidate_events | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _on_resize(self) -> None:
"""
When the window size changes, we erase the current output and request
again the cursor position. When the CPR answer arrives, the output is
drawn again.
"""
# Erase, request position (when cursor is at the start position)
# and re... |
When the window size changes, we erase the current output and request
again the cursor position. When the CPR answer arrives, the output is
drawn again.
| _on_resize | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _pre_run(self, pre_run: Callable[[], None] | None = None) -> None:
"""
Called during `run`.
`self.future` should be set to the new future at the point where this
is called in order to avoid data races. `pre_run` can be used to set a
`threading.Event` to synchronize with UI t... |
Called during `run`.
`self.future` should be set to the new future at the point where this
is called in order to avoid data races. `pre_run` can be used to set a
`threading.Event` to synchronize with UI termination code, running in
another thread that would call `Application.ex... | _pre_run | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
async def run_async(
self,
pre_run: Callable[[], None] | None = None,
set_exception_handler: bool = True,
handle_sigint: bool = True,
slow_callback_duration: float = 0.5,
) -> _AppResult:
"""
Run the prompt_toolkit :class:`~prompt_toolkit.application.Applicati... |
Run the prompt_toolkit :class:`~prompt_toolkit.application.Application`
until :meth:`~prompt_toolkit.application.Application.exit` has been
called. Return the value that was passed to
:meth:`~prompt_toolkit.application.Application.exit`.
This is the main entry point for a promp... | run_async | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def run(
self,
pre_run: Callable[[], None] | None = None,
set_exception_handler: bool = True,
handle_sigint: bool = True,
in_thread: bool = False,
inputhook: InputHook | None = None,
) -> _AppResult:
"""
A blocking 'run' call that waits until the UI is... |
A blocking 'run' call that waits until the UI is finished.
This will run the application in a fresh asyncio event loop.
:param pre_run: Optional callable, which is called right after the
"reset" of the application.
:param set_exception_handler: When set, in case of an exce... | run | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _handle_exception(
self, loop: AbstractEventLoop, context: dict[str, Any]
) -> None:
"""
Handler for event loop exceptions.
This will print the exception, using run_in_terminal.
"""
# For Python 2: we have to get traceback at this point, because
# we're st... |
Handler for event loop exceptions.
This will print the exception, using run_in_terminal.
| _handle_exception | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _enable_breakpointhook(self) -> Generator[None, None, None]:
"""
Install our custom breakpointhook for the duration of this context
manager. (We will only install the hook if no other custom hook was
set.)
"""
if sys.breakpointhook == sys.__breakpointhook__:
... |
Install our custom breakpointhook for the duration of this context
manager. (We will only install the hook if no other custom hook was
set.)
| _enable_breakpointhook | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _breakpointhook(self, *a: object, **kw: object) -> None:
"""
Breakpointhook which uses PDB, but ensures that the application is
hidden and input echoing is restored during each debugger dispatch.
This can be called from any thread. In any case, the application's
event loop w... |
Breakpointhook which uses PDB, but ensures that the application is
hidden and input echoing is restored during each debugger dispatch.
This can be called from any thread. In any case, the application's
event loop will be blocked while the PDB input is displayed. The event
will ... | _breakpointhook | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def hide_app_from_eventloop_thread() -> Generator[None, None, None]:
"""Stop application if `__breakpointhook__` is called from within
the App's event loop."""
# Hide application.
app.renderer.erase()
# Detach input and dispatch to debugger.
with ... | Stop application if `__breakpointhook__` is called from within
the App's event loop. | hide_app_from_eventloop_thread | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def hide_app_from_other_thread() -> Generator[None, None, None]:
"""Stop application if `__breakpointhook__` is called from a
thread other than the App's event loop."""
ready = threading.Event()
done = threading.Event()
async def in_loop() -> None:
... | Stop application if `__breakpointhook__` is called from a
thread other than the App's event loop. | hide_app_from_other_thread | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def create_background_task(
self, coroutine: Coroutine[Any, Any, None]
) -> asyncio.Task[None]:
"""
Start a background task (coroutine) for the running application. When
the `Application` terminates, unfinished background tasks will be
cancelled.
Given that we still ... |
Start a background task (coroutine) for the running application. When
the `Application` terminates, unfinished background tasks will be
cancelled.
Given that we still support Python versions before 3.11, we can't use
task groups (and exception groups), because of that, these ba... | create_background_task | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _on_background_task_done(self, task: asyncio.Task[None]) -> None:
"""
Called when a background task completes. Remove it from
`_background_tasks`, and handle exceptions if any.
"""
self._background_tasks.discard(task)
if task.cancelled():
return
... |
Called when a background task completes. Remove it from
`_background_tasks`, and handle exceptions if any.
| _on_background_task_done | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
async def cancel_and_wait_for_background_tasks(self) -> None:
"""
Cancel all background tasks, and wait for the cancellation to complete.
If any of the background tasks raised an exception, this will also
propagate the exception.
(If we had nurseries like Trio, this would be the... |
Cancel all background tasks, and wait for the cancellation to complete.
If any of the background tasks raised an exception, this will also
propagate the exception.
(If we had nurseries like Trio, this would be the `__aexit__` of a
nursery.)
| cancel_and_wait_for_background_tasks | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
async def _poll_output_size(self) -> None:
"""
Coroutine for polling the terminal dimensions.
Useful for situations where `attach_winch_signal_handler` is not sufficient:
- If we are not running in the main thread.
- On Windows.
"""
size: Size | None = None
... |
Coroutine for polling the terminal dimensions.
Useful for situations where `attach_winch_signal_handler` is not sufficient:
- If we are not running in the main thread.
- On Windows.
| _poll_output_size | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def cpr_not_supported_callback(self) -> None:
"""
Called when we don't receive the cursor position response in time.
"""
if not self.output.responds_to_cpr:
return # We know about this already.
def in_terminal() -> None:
self.output.write(
... |
Called when we don't receive the cursor position response in time.
| cpr_not_supported_callback | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def exit(
self,
result: _AppResult | None = None,
exception: BaseException | type[BaseException] | None = None,
style: str = "",
) -> None:
"""
Exit application.
.. note::
If `Application.exit` is called before `Application.run()` is
... |
Exit application.
.. note::
If `Application.exit` is called before `Application.run()` is
called, then the `Application` won't exit (because the
`Application.future` doesn't correspond to the current run). Use a
`pre_run` hook and an event to synchroniz... | exit | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
async def run_system_command(
self,
command: str,
wait_for_enter: bool = True,
display_before_text: AnyFormattedText = "",
wait_text: str = "Press ENTER to continue...",
) -> None:
"""
Run system command (While hiding the prompt. When finished, all the
... |
Run system command (While hiding the prompt. When finished, all the
output will scroll above the prompt.)
:param command: Shell command to be executed.
:param wait_for_enter: FWait for the user to press enter, when the
command is finished.
:param display_before_text... | run_system_command | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def suspend_to_background(self, suspend_group: bool = True) -> None:
"""
(Not thread safe -- to be called from inside the key bindings.)
Suspend process.
:param suspend_group: When true, suspend the whole process group.
(This is the default, and probably what you want.)
... |
(Not thread safe -- to be called from inside the key bindings.)
Suspend process.
:param suspend_group: When true, suspend the whole process group.
(This is the default, and probably what you want.)
| suspend_to_background | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def print_text(
self, text: AnyFormattedText, style: BaseStyle | None = None
) -> None:
"""
Print a list of (style_str, text) tuples to the output.
(When the UI is running, this method has to be called through
`run_in_terminal`, otherwise it will destroy the UI.)
:pa... |
Print a list of (style_str, text) tuples to the output.
(When the UI is running, this method has to be called through
`run_in_terminal`, otherwise it will destroy the UI.)
:param text: List of ``(style_str, text)`` tuples.
:param style: Style class to use. Defaults to the activ... | print_text | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def get_used_style_strings(self) -> list[str]:
"""
Return a list of used style strings. This is helpful for debugging, and
for writing a new `Style`.
"""
attrs_for_style = self.renderer._attrs_for_style
if attrs_for_style:
return sorted(
re.su... |
Return a list of used style strings. This is helpful for debugging, and
for writing a new `Style`.
| get_used_style_strings | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def _create_key_bindings(
self, current_window: Window, other_controls: list[UIControl]
) -> KeyBindingsBase:
"""
Create a `KeyBindings` object that merges the `KeyBindings` from the
`UIControl` with all the parent controls and the global key bindings.
"""
key_binding... |
Create a `KeyBindings` object that merges the `KeyBindings` from the
`UIControl` with all the parent controls and the global key bindings.
| _create_key_bindings | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
async def _do_wait_for_enter(wait_text: AnyFormattedText) -> None:
"""
Create a sub application to wait for the enter key press.
This has two advantages over using 'input'/'raw_input':
- This will share the same input/output I/O.
- This doesn't block the event loop.
"""
from prompt_toolkit.s... |
Create a sub application to wait for the enter key press.
This has two advantages over using 'input'/'raw_input':
- This will share the same input/output I/O.
- This doesn't block the event loop.
| _do_wait_for_enter | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def attach_winch_signal_handler(
handler: Callable[[], None],
) -> Generator[None, None, None]:
"""
Attach the given callback as a WINCH signal handler within the context
manager. Restore the original signal handler when done.
The `Application.run` method will register SIGWINCH, so that it will
... |
Attach the given callback as a WINCH signal handler within the context
manager. Restore the original signal handler when done.
The `Application.run` method will register SIGWINCH, so that it will
properly repaint when the terminal window resizes. However, using
`run_in_terminal`, we can temporaril... | attach_winch_signal_handler | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/application.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/application.py | BSD-3-Clause |
def get_app() -> Application[Any]:
"""
Get the current active (running) Application.
An :class:`.Application` is active during the
:meth:`.Application.run_async` call.
We assume that there can only be one :class:`.Application` active at the
same time. There is only one terminal window, with onl... |
Get the current active (running) Application.
An :class:`.Application` is active during the
:meth:`.Application.run_async` call.
We assume that there can only be one :class:`.Application` active at the
same time. There is only one terminal window, with only one stdin and
stdout. This makes the... | get_app | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/current.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/current.py | BSD-3-Clause |
def set_app(app: Application[Any]) -> Generator[None, None, None]:
"""
Context manager that sets the given :class:`.Application` active in an
`AppSession`.
This should only be called by the `Application` itself.
The application will automatically be active while its running. If you want
the app... |
Context manager that sets the given :class:`.Application` active in an
`AppSession`.
This should only be called by the `Application` itself.
The application will automatically be active while its running. If you want
the application to be active in other threads/coroutines, where that's not
th... | set_app | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/current.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/current.py | BSD-3-Clause |
def create_app_session(
input: Input | None = None, output: Output | None = None
) -> Generator[AppSession, None, None]:
"""
Create a separate AppSession.
This is useful if there can be multiple individual ``AppSession``'s going
on. Like in the case of a Telnet/SSH server.
"""
# If no input... |
Create a separate AppSession.
This is useful if there can be multiple individual ``AppSession``'s going
on. Like in the case of a Telnet/SSH server.
| create_app_session | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/current.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/current.py | BSD-3-Clause |
def create_app_session_from_tty() -> Generator[AppSession, None, None]:
"""
Create `AppSession` that always prefers the TTY input/output.
Even if `sys.stdin` and `sys.stdout` are connected to input/output pipes,
this will still use the terminal for interaction (because `sys.stderr` is
still connect... |
Create `AppSession` that always prefers the TTY input/output.
Even if `sys.stdin` and `sys.stdout` are connected to input/output pipes,
this will still use the terminal for interaction (because `sys.stderr` is
still connected to the terminal).
Usage::
from prompt_toolkit.shortcuts import... | create_app_session_from_tty | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/current.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/current.py | BSD-3-Clause |
def run_in_terminal(
func: Callable[[], _T], render_cli_done: bool = False, in_executor: bool = False
) -> Awaitable[_T]:
"""
Run function on the terminal above the current application or prompt.
What this does is first hiding the prompt, then running this callable
(which can safely output to the t... |
Run function on the terminal above the current application or prompt.
What this does is first hiding the prompt, then running this callable
(which can safely output to the terminal), and then again rendering the
prompt which causes the output of this function to scroll above the
prompt.
``fun... | run_in_terminal | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/run_in_terminal.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/run_in_terminal.py | BSD-3-Clause |
async def in_terminal(render_cli_done: bool = False) -> AsyncGenerator[None, None]:
"""
Asynchronous context manager that suspends the current application and runs
the body in the terminal.
.. code::
async def f():
async with in_terminal():
call_some_function()
... |
Asynchronous context manager that suspends the current application and runs
the body in the terminal.
.. code::
async def f():
async with in_terminal():
call_some_function()
await call_some_async_function()
| in_terminal | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/application/run_in_terminal.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/application/run_in_terminal.py | BSD-3-Clause |
def set_data(self, data: ClipboardData) -> None:
"""
Set data to the clipboard.
:param data: :class:`~.ClipboardData` instance.
""" |
Set data to the clipboard.
:param data: :class:`~.ClipboardData` instance.
| set_data | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/clipboard/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/clipboard/base.py | BSD-3-Clause |
def rotate(self) -> None:
"""
For Emacs mode, rotate the kill ring.
""" |
For Emacs mode, rotate the kill ring.
| rotate | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/clipboard/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/clipboard/base.py | BSD-3-Clause |
def display_text(self) -> str:
"The 'display' field as plain text."
from prompt_toolkit.formatted_text import fragment_list_to_text
return fragment_list_to_text(self.display) | The 'display' field as plain text. | display_text | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def display_meta(self) -> StyleAndTextTuples:
"Return meta-text. (This is lazy when using a callable)."
from prompt_toolkit.formatted_text import to_formatted_text
return to_formatted_text(self._display_meta or "") | Return meta-text. (This is lazy when using a callable). | display_meta | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def display_meta_text(self) -> str:
"The 'meta' field as plain text."
from prompt_toolkit.formatted_text import fragment_list_to_text
return fragment_list_to_text(self.display_meta) | The 'meta' field as plain text. | display_meta_text | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def new_completion_from_position(self, position: int) -> Completion:
"""
(Only for internal use!)
Get a new completion by splitting this one. Used by `Application` when
it needs to have a list of new completions after inserting the common
prefix.
"""
assert positi... |
(Only for internal use!)
Get a new completion by splitting this one. Used by `Application` when
it needs to have a list of new completions after inserting the common
prefix.
| new_completion_from_position | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def get_completions(
self, document: Document, complete_event: CompleteEvent
) -> Iterable[Completion]:
"""
This should be a generator that yields :class:`.Completion` instances.
If the generation of completions is something expensive (that takes a
lot of time), consider wra... |
This should be a generator that yields :class:`.Completion` instances.
If the generation of completions is something expensive (that takes a
lot of time), consider wrapping this `Completer` class in a
`ThreadedCompleter`. In that case, the completer algorithm runs in a
backgrou... | get_completions | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
async def get_completions_async(
self, document: Document, complete_event: CompleteEvent
) -> AsyncGenerator[Completion, None]:
"""
Asynchronous generator for completions. (Probably, you won't have to
override this.)
Asynchronous generator of :class:`.Completion` objects.
... |
Asynchronous generator for completions. (Probably, you won't have to
override this.)
Asynchronous generator of :class:`.Completion` objects.
| get_completions_async | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def merge_completers(
completers: Sequence[Completer], deduplicate: bool = False
) -> Completer:
"""
Combine several completers into one.
:param deduplicate: If `True`, wrap the result in a `DeduplicateCompleter`
so that completions that would result in the same text will be
deduplicate... |
Combine several completers into one.
:param deduplicate: If `True`, wrap the result in a `DeduplicateCompleter`
so that completions that would result in the same text will be
deduplicated.
| merge_completers | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def get_common_complete_suffix(
document: Document, completions: Sequence[Completion]
) -> str:
"""
Return the common prefix for all completions.
"""
# Take only completions that don't change the text before the cursor.
def doesnt_change_before_cursor(completion: Completion) -> bool:
en... |
Return the common prefix for all completions.
| get_common_complete_suffix | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/base.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py | BSD-3-Clause |
def sort_key(fuzzy_match: _FuzzyMatch) -> tuple[int, int]:
"Sort by start position, then by the length of the match."
return fuzzy_match.start_pos, fuzzy_match.match_length | Sort by start position, then by the length of the match. | sort_key | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/fuzzy_completer.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/fuzzy_completer.py | BSD-3-Clause |
def _get_display(
self, fuzzy_match: _FuzzyMatch, word_before_cursor: str
) -> AnyFormattedText:
"""
Generate formatted text for the display label.
"""
def get_display() -> AnyFormattedText:
m = fuzzy_match
word = m.completion.text
if m.m... |
Generate formatted text for the display label.
| _get_display | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/fuzzy_completer.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/fuzzy_completer.py | BSD-3-Clause |
def from_nested_dict(cls, data: NestedDict) -> NestedCompleter:
"""
Create a `NestedCompleter`, starting from a nested dictionary data
structure, like this:
.. code::
data = {
'show': {
'version': None,
'interfaces': N... |
Create a `NestedCompleter`, starting from a nested dictionary data
structure, like this:
.. code::
data = {
'show': {
'version': None,
'interfaces': None,
'clock': None,
'ip': {'interfa... | from_nested_dict | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/nested.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/nested.py | BSD-3-Clause |
def word_matches(word: str) -> bool:
"""True when the word before the cursor matches."""
if self.ignore_case:
word = word.lower()
if self.match_middle:
return word_before_cursor in word
else:
return word.startswith(word_bef... | True when the word before the cursor matches. | word_matches | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/completion/word_completer.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/word_completer.py | BSD-3-Clause |
def escape(self, varname: str, value: str) -> str:
"""
Escape `value` to fit in the place of this variable into the grammar.
"""
f = self.escape_funcs.get(varname)
return f(value) if f else value |
Escape `value` to fit in the place of this variable into the grammar.
| escape | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def _transform(
cls, root_node: Node, create_group_func: Callable[[Variable], str]
) -> str:
"""
Turn a :class:`Node` object into a regular expression.
:param root_node: The :class:`Node` instance for which we generate the grammar.
:param create_group_func: A callable which ... |
Turn a :class:`Node` object into a regular expression.
:param root_node: The :class:`Node` instance for which we generate the grammar.
:param create_group_func: A callable which takes a `Node` and returns the next
free name for this node.
| _transform | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def _transform_prefix(
cls, root_node: Node, create_group_func: Callable[[Variable], str]
) -> Iterable[str]:
"""
Yield all the regular expressions matching a prefix of the grammar
defined by the `Node` instance.
For each `Variable`, one regex pattern will be generated, with... |
Yield all the regular expressions matching a prefix of the grammar
defined by the `Node` instance.
For each `Variable`, one regex pattern will be generated, with this
named group at the end. This is required because a regex engine will
terminate once a match is found. For autoc... | _transform_prefix | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def match(self, string: str) -> Match | None:
"""
Match the string with the grammar.
Returns a :class:`Match` instance or `None` when the input doesn't match the grammar.
:param string: The input string.
"""
m = self._re.match(string)
if m:
return Ma... |
Match the string with the grammar.
Returns a :class:`Match` instance or `None` when the input doesn't match the grammar.
:param string: The input string.
| match | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def match_prefix(self, string: str) -> Match | None:
"""
Do a partial match of the string with the grammar. The returned
:class:`Match` instance can contain multiple representations of the
match. This will never return `None`. If it doesn't match at all, the "trailing input"
part... |
Do a partial match of the string with the grammar. The returned
:class:`Match` instance can contain multiple representations of the
match. This will never return `None`. If it doesn't match at all, the "trailing input"
part will capture all of the input.
:param string: The inpu... | match_prefix | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def _nodes_to_regs(self) -> list[tuple[str, tuple[int, int]]]:
"""
Return a list of (varname, reg) tuples.
"""
def get_tuples() -> Iterable[tuple[str, tuple[int, int]]]:
for r, re_match in self._re_matches:
for group_name, group_index in r.groupindex.items():... |
Return a list of (varname, reg) tuples.
| _nodes_to_regs | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def trailing_input(self) -> MatchVariable | None:
"""
Get the `MatchVariable` instance, representing trailing input, if there is any.
"Trailing input" is input at the end that does not match the grammar anymore, but
when this is removed from the end of the input, the input would be a val... |
Get the `MatchVariable` instance, representing trailing input, if there is any.
"Trailing input" is input at the end that does not match the grammar anymore, but
when this is removed from the end of the input, the input would be a valid string.
| trailing_input | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def end_nodes(self) -> Iterable[MatchVariable]:
"""
Yields `MatchVariable` instances for all the nodes having their end
position at the end of the input string.
"""
for varname, reg in self._nodes_to_regs():
# If this part goes until the end of the input string.
... |
Yields `MatchVariable` instances for all the nodes having their end
position at the end of the input string.
| end_nodes | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def compile(
expression: str,
escape_funcs: EscapeFuncDict | None = None,
unescape_funcs: EscapeFuncDict | None = None,
) -> _CompiledGrammar:
"""
Compile grammar (given as regex string), returning a `CompiledGrammar`
instance.
"""
return _compile_from_parse_tree(
parse_regex(tok... |
Compile grammar (given as regex string), returning a `CompiledGrammar`
instance.
| compile | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def _compile_from_parse_tree(
root_node: Node,
escape_funcs: EscapeFuncDict | None = None,
unescape_funcs: EscapeFuncDict | None = None,
) -> _CompiledGrammar:
"""
Compile grammar (given as parse tree), returning a `CompiledGrammar`
instance.
"""
return _CompiledGrammar(
root_nod... |
Compile grammar (given as parse tree), returning a `CompiledGrammar`
instance.
| _compile_from_parse_tree | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/compiler.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/compiler.py | BSD-3-Clause |
def _get_completions_for_match(
self, match: Match, complete_event: CompleteEvent
) -> Iterable[Completion]:
"""
Yield all the possible completions for this input string.
(The completer assumes that the cursor position was at the end of the
input string.)
"""
... |
Yield all the possible completions for this input string.
(The completer assumes that the cursor position was at the end of the
input string.)
| _get_completions_for_match | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/completion.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/completion.py | BSD-3-Clause |
def _remove_duplicates(self, items: Iterable[Completion]) -> Iterable[Completion]:
"""
Remove duplicates, while keeping the order.
(Sometimes we have duplicates, because the there several matches of the
same grammar, each yielding similar completions.)
"""
def hash_compl... |
Remove duplicates, while keeping the order.
(Sometimes we have duplicates, because the there several matches of the
same grammar, each yielding similar completions.)
| _remove_duplicates | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/completion.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/completion.py | BSD-3-Clause |
def tokenize_regex(input: str) -> list[str]:
"""
Takes a string, representing a regular expression as input, and tokenizes
it.
:param input: string, representing a regular expression.
:returns: List of tokens.
"""
# Regular expression for tokenizing other regular expressions.
p = re.com... |
Takes a string, representing a regular expression as input, and tokenizes
it.
:param input: string, representing a regular expression.
:returns: List of tokens.
| tokenize_regex | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/regex_parser.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/regex_parser.py | BSD-3-Clause |
def parse_regex(regex_tokens: list[str]) -> Node:
"""
Takes a list of tokens from the tokenizer, and returns a parse tree.
"""
# We add a closing brace because that represents the final pop of the stack.
tokens: list[str] = [")"] + regex_tokens[::-1]
def wrap(lst: list[Node]) -> Node:
"... |
Takes a list of tokens from the tokenizer, and returns a parse tree.
| parse_regex | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/regex_parser.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/regex_parser.py | BSD-3-Clause |
def wrap(lst: list[Node]) -> Node:
"""Turn list into sequence when it contains several items."""
if len(lst) == 1:
return lst[0]
else:
return NodeSequence(lst) | Turn list into sequence when it contains several items. | wrap | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/regular_languages/regex_parser.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/regular_languages/regex_parser.py | BSD-3-Clause |
def _get_size(self) -> Size:
"""
Callable that returns the current `Size`, required by Vt100_Output.
"""
if self._chan is None:
return Size(rows=20, columns=79)
else:
width, height, pixwidth, pixheight = self._chan.get_terminal_size()
return Si... |
Callable that returns the current `Size`, required by Vt100_Output.
| _get_size | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/ssh/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/ssh/server.py | BSD-3-Clause |
def _parse_coroutine(self) -> Generator[None, bytes, None]:
"""
Parser state machine.
Every 'yield' expression returns the next byte.
"""
while True:
d = yield
if d == int2byte(0):
pass # NOP
# Go to state escaped.
... |
Parser state machine.
Every 'yield' expression returns the next byte.
| _parse_coroutine | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/protocol.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/protocol.py | BSD-3-Clause |
def send_above_prompt(self, formatted_text: AnyFormattedText) -> None:
"""
Send text to the client.
This is asynchronous, returns a `Future`.
"""
formatted_text = to_formatted_text(formatted_text)
return self._run_in_terminal(lambda: self.send(formatted_text)) |
Send text to the client.
This is asynchronous, returns a `Future`.
| send_above_prompt | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/server.py | BSD-3-Clause |
def erase_screen(self) -> None:
"""
Erase the screen and move the cursor to the top.
"""
if self.vt100_output is None:
return
self.vt100_output.erase_screen()
self.vt100_output.cursor_goto(0, 0)
self.vt100_output.flush() |
Erase the screen and move the cursor to the top.
| erase_screen | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/server.py | BSD-3-Clause |
async def run(self, ready_cb: Callable[[], None] | None = None) -> None:
"""
Run the telnet server, until this gets cancelled.
:param ready_cb: Callback that will be called at the point that we're
actually listening.
"""
socket = self._create_socket(self.host, self.p... |
Run the telnet server, until this gets cancelled.
:param ready_cb: Callback that will be called at the point that we're
actually listening.
| run | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/server.py | BSD-3-Clause |
def start(self) -> None:
"""
Deprecated: Use `.run()` instead.
Start the telnet server (stop by calling and awaiting `stop()`).
"""
if self._run_task is not None:
# Already running.
return
self._run_task = get_running_loop().create_task(self.run(... |
Deprecated: Use `.run()` instead.
Start the telnet server (stop by calling and awaiting `stop()`).
| start | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/server.py | BSD-3-Clause |
async def stop(self) -> None:
"""
Deprecated: Use `.run()` instead.
Stop a telnet server that was started using `.start()` and wait for the
cancellation to complete.
"""
if self._run_task is not None:
self._run_task.cancel()
try:
a... |
Deprecated: Use `.run()` instead.
Stop a telnet server that was started using `.start()` and wait for the
cancellation to complete.
| stop | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/contrib/telnet/server.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/contrib/telnet/server.py | BSD-3-Clause |
async def aclosing(
thing: _T_Generator,
) -> AsyncGenerator[_T_Generator, None]:
"Similar to `contextlib.aclosing`, in Python 3.10."
try:
yield thing
finally:
await thing.aclose() | Similar to `contextlib.aclosing`, in Python 3.10. | aclosing | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/async_generator.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/async_generator.py | BSD-3-Clause |
async def generator_to_async_generator(
get_iterable: Callable[[], Iterable[_T]],
buffer_size: int = DEFAULT_BUFFER_SIZE,
) -> AsyncGenerator[_T, None]:
"""
Turn a generator or iterable into an async generator.
This works by running the generator in a background thread.
:param get_iterable: Fu... |
Turn a generator or iterable into an async generator.
This works by running the generator in a background thread.
:param get_iterable: Function that returns a generator or iterable when
called.
:param buffer_size: Size of the queue between the async consumer and the
synchronous genera... | generator_to_async_generator | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/async_generator.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/async_generator.py | BSD-3-Clause |
def runner() -> None:
"""
Consume the generator in background thread.
When items are received, they'll be pushed to the queue.
"""
try:
for item in get_iterable():
# When this async generator was cancelled (closed), stop this
# thread.
... |
Consume the generator in background thread.
When items are received, they'll be pushed to the queue.
| runner | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/async_generator.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/async_generator.py | BSD-3-Clause |
def new_eventloop_with_inputhook(
inputhook: Callable[[InputHookContext], None],
) -> AbstractEventLoop:
"""
Create a new event loop with the given inputhook.
"""
selector = InputHookSelector(selectors.DefaultSelector(), inputhook)
loop = asyncio.SelectorEventLoop(selector)
return loop |
Create a new event loop with the given inputhook.
| new_eventloop_with_inputhook | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/inputhook.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/inputhook.py | BSD-3-Clause |
def set_eventloop_with_inputhook(
inputhook: Callable[[InputHookContext], None],
) -> AbstractEventLoop:
"""
Create a new event loop with the given inputhook, and activate it.
"""
# Deprecated!
loop = new_eventloop_with_inputhook(inputhook)
asyncio.set_event_loop(loop)
return loop |
Create a new event loop with the given inputhook, and activate it.
| set_eventloop_with_inputhook | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/inputhook.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/inputhook.py | BSD-3-Clause |
def run_in_executor_with_context(
func: Callable[..., _T],
*args: Any,
loop: asyncio.AbstractEventLoop | None = None,
) -> Awaitable[_T]:
"""
Run a function in an executor, but make sure it uses the same contextvars.
This is required so that the function will see the right application.
See ... |
Run a function in an executor, but make sure it uses the same contextvars.
This is required so that the function will see the right application.
See also: https://bugs.python.org/issue34014
| run_in_executor_with_context | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/utils.py | BSD-3-Clause |
def call_soon_threadsafe(
func: Callable[[], None],
max_postpone_time: float | None = None,
loop: asyncio.AbstractEventLoop | None = None,
) -> None:
"""
Wrapper around asyncio's `call_soon_threadsafe`.
This takes a `max_postpone_time` which can be used to tune the urgency of
the method.
... |
Wrapper around asyncio's `call_soon_threadsafe`.
This takes a `max_postpone_time` which can be used to tune the urgency of
the method.
Asyncio runs tasks in first-in-first-out. However, this is not what we
want for the render function of the prompt_toolkit UI. Rendering is
expensive, but sinc... | call_soon_threadsafe | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/utils.py | BSD-3-Clause |
def get_traceback_from_context(context: dict[str, Any]) -> TracebackType | None:
"""
Get the traceback object from the context.
"""
exception = context.get("exception")
if exception:
if hasattr(exception, "__traceback__"):
return cast(TracebackType, exception.__traceback__)
... |
Get the traceback object from the context.
| get_traceback_from_context | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/utils.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/utils.py | BSD-3-Clause |
def wait_for_handles(handles: list[HANDLE], timeout: int = INFINITE) -> HANDLE | None:
"""
Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
Returns `None` on timeout.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
Note that handles... |
Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
Returns `None` on timeout.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
Note that handles should be a list of `HANDLE` objects, not integers. See
this comment in the patch by @qua... | wait_for_handles | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/win32.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/win32.py | BSD-3-Clause |
def create_win32_event() -> HANDLE:
"""
Creates a Win32 unnamed Event .
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
"""
return HANDLE(
windll.kernel32.CreateEventA(
pointer(SECURITY_ATTRIBUTES()),
BOOL(True), # Manual reset event.
... |
Creates a Win32 unnamed Event .
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
| create_win32_event | python | prompt-toolkit/python-prompt-toolkit | src/prompt_toolkit/eventloop/win32.py | https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/eventloop/win32.py | BSD-3-Clause |
def has_focus(value: FocusableElement) -> Condition:
"""
Enable when this buffer has the focus.
"""
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.layout import walk
from prompt_toolkit.layout.containers import Container, Window, to_container
from prompt_toolkit.layout.controls... |
Enable when this buffer has the focus.
| has_focus | 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_suggestion() -> bool:
"""
Enable when the current buffer has a suggestion.
"""
buffer = get_app().current_buffer
return buffer.suggestion is not None and buffer.suggestion.text != "" |
Enable when the current buffer has a suggestion.
| has_suggestion | 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_completions() -> bool:
"""
Enable when the current buffer has completions.
"""
state = get_app().current_buffer.complete_state
return state is not None and len(state.completions) > 0 |
Enable when the current buffer has completions.
| has_completions | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.