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 swap_characters_before_cursor(self) -> None: """ Swap the last two characters before the cursor. """ pos = self.cursor_position if pos >= 2: a = self.text[pos - 2] b = self.text[pos - 1] self.text = self.text[: pos - 2] + b + a + self.tex...
Swap the last two characters before the cursor.
swap_characters_before_cursor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def go_to_history(self, index: int) -> None: """ Go to this item in the history. """ if index < len(self._working_lines): self.working_index = index self.cursor_position = len(self.text)
Go to this item in the history.
go_to_history
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def complete_next(self, count: int = 1, disable_wrap_around: bool = False) -> None: """ Browse to the next completions. (Does nothing if there are no completion.) """ index: int | None if self.complete_state: completions_count = len(self.complete_state.comple...
Browse to the next completions. (Does nothing if there are no completion.)
complete_next
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def complete_previous( self, count: int = 1, disable_wrap_around: bool = False ) -> None: """ Browse to the previous completions. (Does nothing if there are no completion.) """ index: int | None if self.complete_state: if self.complete_state.compl...
Browse to the previous completions. (Does nothing if there are no completion.)
complete_previous
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def cancel_completion(self) -> None: """ Cancel completion, go back to the original text. """ if self.complete_state: self.go_to_completion(None) self.complete_state = None
Cancel completion, go back to the original text.
cancel_completion
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _set_completions(self, completions: list[Completion]) -> CompletionState: """ Start completions. (Generate list of completions and initialize.) By default, no completion will be selected. """ self.complete_state = CompletionState( original_document=self.document,...
Start completions. (Generate list of completions and initialize.) By default, no completion will be selected.
_set_completions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def start_history_lines_completion(self) -> None: """ Start a completion based on all the other lines in the document and the history. """ found_completions: set[str] = set() completions = [] # For every line of the whole history, find matches with the current li...
Start a completion based on all the other lines in the document and the history.
start_history_lines_completion
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def go_to_completion(self, index: int | None) -> None: """ Select a completion from the list of current completions. """ assert self.complete_state # Set new completion state = self.complete_state state.go_to_index(index) # Set text/cursor position ...
Select a completion from the list of current completions.
go_to_completion
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _set_history_search(self) -> None: """ Set `history_search_text`. (The text before the cursor will be used for filtering the history.) """ if self.enable_history_search(): if self.history_search_text is None: self.history_search_text = self.documen...
Set `history_search_text`. (The text before the cursor will be used for filtering the history.)
_set_history_search
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def history_forward(self, count: int = 1) -> None: """ Move forwards through the history. :param count: Amount of items to move forward. """ self._set_history_search() # Go forward in history. found_something = False for i in range(self.working_index + ...
Move forwards through the history. :param count: Amount of items to move forward.
history_forward
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def yank_nth_arg(self, n: int | None = None, _yank_last_arg: bool = False) -> None: """ Pick nth word from previous history entry (depending on current `yank_nth_arg_state`) and insert it at current position. Rotate through history if called repeatedly. If no `n` has been given, take the...
Pick nth word from previous history entry (depending on current `yank_nth_arg_state`) and insert it at current position. Rotate through history if called repeatedly. If no `n` has been given, take the first argument. (The second word.) :param n: (None or int), The index of the ...
yank_nth_arg
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def start_selection( self, selection_type: SelectionType = SelectionType.CHARACTERS ) -> None: """ Take the current cursor position as the start of this selection. """ self.selection_state = SelectionState(self.cursor_position, selection_type)
Take the current cursor position as the start of this selection.
start_selection
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def copy_selection(self, _cut: bool = False) -> ClipboardData: """ Copy selected text and return :class:`.ClipboardData` instance. Notice that this doesn't store the copied data on the clipboard yet. You can store it like this: .. code:: python data = buffer.copy_s...
Copy selected text and return :class:`.ClipboardData` instance. Notice that this doesn't store the copied data on the clipboard yet. You can store it like this: .. code:: python data = buffer.copy_selection() get_app().clipboard.set_data(data)
copy_selection
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def paste_clipboard_data( self, data: ClipboardData, paste_mode: PasteMode = PasteMode.EMACS, count: int = 1, ) -> None: """ Insert the data from the clipboard. """ assert isinstance(data, ClipboardData) assert paste_mode in (PasteMode.VI_BEFOR...
Insert the data from the clipboard.
paste_clipboard_data
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def newline(self, copy_margin: bool = True) -> None: """ Insert a line ending at the current position. """ if copy_margin: self.insert_text("\n" + self.document.leading_whitespace_in_current_line) else: self.insert_text("\n")
Insert a line ending at the current position.
newline
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def insert_line_above(self, copy_margin: bool = True) -> None: """ Insert a new line above the current one. """ if copy_margin: insert = self.document.leading_whitespace_in_current_line + "\n" else: insert = "\n" self.cursor_position += self.docum...
Insert a new line above the current one.
insert_line_above
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def insert_line_below(self, copy_margin: bool = True) -> None: """ Insert a new line below the current one. """ if copy_margin: insert = "\n" + self.document.leading_whitespace_in_current_line else: insert = "\n" self.cursor_position += self.docum...
Insert a new line below the current one.
insert_line_below
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def insert_text( self, data: str, overwrite: bool = False, move_cursor: bool = True, fire_event: bool = True, ) -> None: """ Insert characters at cursor position. :param fire_event: Fire `on_text_insert` event. This is mainly used to trigg...
Insert characters at cursor position. :param fire_event: Fire `on_text_insert` event. This is mainly used to trigger autocompletion while typing.
insert_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def validate(self, set_cursor: bool = False) -> bool: """ Returns `True` if valid. :param set_cursor: Set the cursor position, if an error was found. """ # Don't call the validator again, if it was already called for the # current input. if self.validation_state ...
Returns `True` if valid. :param set_cursor: Set the cursor position, if an error was found.
validate
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
async def _validate_async(self) -> None: """ Asynchronous version of `validate()`. This one doesn't set the cursor position. We have both variants, because a synchronous version is required. Handling the ENTER key needs to be completely synchronous, otherwise stuff like ...
Asynchronous version of `validate()`. This one doesn't set the cursor position. We have both variants, because a synchronous version is required. Handling the ENTER key needs to be completely synchronous, otherwise stuff like type-ahead is going to give very weird results. (Peo...
_validate_async
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def append_to_history(self) -> None: """ Append the current input to the history. """ # Save at the tail of the history. (But don't if the last entry the # history is already the same.) if self.text: history_strings = self.history.get_strings() if ...
Append the current input to the history.
append_to_history
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _search( self, search_state: SearchState, include_current_position: bool = False, count: int = 1, ) -> tuple[int, int] | None: """ Execute search. Return (working_index, cursor_position) tuple when this search is applied. Returns `None` when this text cann...
Execute search. Return (working_index, cursor_position) tuple when this search is applied. Returns `None` when this text cannot be found.
_search
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def search_once( working_index: int, document: Document ) -> tuple[int, Document] | None: """ Do search one time. Return (working_index, document) or `None` """ if direction == SearchDirection.FORWARD: # Try find at the curr...
Do search one time. Return (working_index, document) or `None`
search_once
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def document_for_search(self, search_state: SearchState) -> Document: """ Return a :class:`~prompt_toolkit.document.Document` instance that has the text/cursor position for this search, if we would apply it. This will be used in the :class:`~prompt_toolkit.layout.BufferControl` t...
Return a :class:`~prompt_toolkit.document.Document` instance that has the text/cursor position for this search, if we would apply it. This will be used in the :class:`~prompt_toolkit.layout.BufferControl` to display feedback while searching.
document_for_search
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def get_search_position( self, search_state: SearchState, include_current_position: bool = True, count: int = 1, ) -> int: """ Get the cursor position for this search. (This operation won't change the `working_index`. It's won't go through the history....
Get the cursor position for this search. (This operation won't change the `working_index`. It's won't go through the history. Vi text objects can't span multiple items.)
get_search_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def apply_search( self, search_state: SearchState, include_current_position: bool = True, count: int = 1, ) -> None: """ Apply search. If something is found, set `working_index` and `cursor_position`. """ search_result = self._search( ...
Apply search. If something is found, set `working_index` and `cursor_position`.
apply_search
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _editor_simple_tempfile(self) -> tuple[str, Callable[[], None]]: """ Simple (file) tempfile implementation. Return (tempfile, cleanup_func). """ suffix = to_str(self.tempfile_suffix) descriptor, filename = tempfile.mkstemp(suffix) os.write(descriptor, self.te...
Simple (file) tempfile implementation. Return (tempfile, cleanup_func).
_editor_simple_tempfile
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def open_in_editor(self, validate_and_handle: bool = False) -> asyncio.Task[None]: """ Open code in editor. This returns a future, and runs in a thread executor. """ if self.read_only(): raise EditReadOnlyBuffer() # Write current text to temporary file ...
Open code in editor. This returns a future, and runs in a thread executor.
open_in_editor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _open_file_in_editor(self, filename: str) -> bool: """ Call editor executable. Return True when we received a zero return code. """ # If the 'VISUAL' or 'EDITOR' environment variable has been set, use that. # Otherwise, fall back to the first available editor that we...
Call editor executable. Return True when we received a zero return code.
_open_file_in_editor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def start_completion( self, select_first: bool = False, select_last: bool = False, insert_common_part: bool = False, complete_event: CompleteEvent | None = None, ) -> None: """ Start asynchronous autocompletion of this buffer. (This will do nothing if ...
Start asynchronous autocompletion of this buffer. (This will do nothing if a previous completion was still in progress.)
start_completion
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _create_completer_coroutine(self) -> Callable[..., Coroutine[Any, Any, None]]: """ Create function for asynchronous autocompletion. (This consumes the asynchronous completer generator, which possibly runs the completion algorithm in another thread.) """ def completi...
Create function for asynchronous autocompletion. (This consumes the asynchronous completer generator, which possibly runs the completion algorithm in another thread.)
_create_completer_coroutine
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def completion_does_nothing(document: Document, completion: Completion) -> bool: """ Return `True` if applying this completion doesn't have any effect. (When it doesn't insert any new text. """ text_before_cursor = document.text_before_cursor repla...
Return `True` if applying this completion doesn't have any effect. (When it doesn't insert any new text.
completion_does_nothing
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
async def refresh_while_loading() -> None: """Background loop to refresh the UI at most 3 times a second while the completion are loading. Calling `on_completions_changed.fire()` for every completion that we receive is too expensive when there are many com...
Background loop to refresh the UI at most 3 times a second while the completion are loading. Calling `on_completions_changed.fire()` for every completion that we receive is too expensive when there are many completions. (We could tune `Application.max_rend...
refresh_while_loading
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _create_auto_suggest_coroutine(self) -> Callable[[], Coroutine[Any, Any, None]]: """ Create function for asynchronous auto suggestion. (This can be in another thread.) """ @_only_one_at_a_time async def async_suggestor() -> None: document = self.document ...
Create function for asynchronous auto suggestion. (This can be in another thread.)
_create_auto_suggest_coroutine
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _create_auto_validate_coroutine( self, ) -> Callable[[], Coroutine[Any, Any, None]]: """ Create a function for asynchronous validation while typing. (This can be in another thread.) """ @_only_one_at_a_time async def async_validator() -> None: ...
Create a function for asynchronous validation while typing. (This can be in another thread.)
_create_auto_validate_coroutine
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def validate_and_handle(self) -> None: """ Validate buffer and handle the accept action. """ valid = self.validate(set_cursor=True) # When the validation succeeded, accept the input. if valid: if self.accept_handler: keep_text = self.accept_ha...
Validate buffer and handle the accept action.
validate_and_handle
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def _only_one_at_a_time(coroutine: _T) -> _T: """ Decorator that only starts the coroutine only if the previous call has finished. (Used to make sure that we have only one autocompleter, auto suggestor and validator running at a time.) When the coroutine raises `_Retry`, it is restarted. """ ...
Decorator that only starts the coroutine only if the previous call has finished. (Used to make sure that we have only one autocompleter, auto suggestor and validator running at a time.) When the coroutine raises `_Retry`, it is restarted.
_only_one_at_a_time
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def indent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None: """ Indent text of a :class:`.Buffer` object. """ current_row = buffer.document.cursor_position_row current_col = buffer.document.cursor_position_col line_range = range(from_row, to_row) # Apply transformation. ...
Indent text of a :class:`.Buffer` object.
indent
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def unindent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None: """ Unindent text of a :class:`.Buffer` object. """ current_row = buffer.document.cursor_position_row current_col = buffer.document.cursor_position_col line_range = range(from_row, to_row) indent_content = " ...
Unindent text of a :class:`.Buffer` object.
unindent
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def reshape_text(buffer: Buffer, from_row: int, to_row: int) -> None: """ Reformat text, taking the width into account. `to_row` is included. (Vi 'gq' operator.) """ lines = buffer.text.splitlines(True) lines_before = lines[:from_row] lines_after = lines[to_row + 1 :] lines_to_reform...
Reformat text, taking the width into account. `to_row` is included. (Vi 'gq' operator.)
reshape_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/buffer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/buffer.py
BSD-3-Clause
def get(self, key: _T, getter_func: Callable[[], _U]) -> _U: """ Get object from the cache. If not found, call `getter_func` to resolve it, and put that on the top of the cache instead. """ # Look in cache first. try: return self._data[key] exc...
Get object from the cache. If not found, call `getter_func` to resolve it, and put that on the top of the cache instead.
get
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/cache.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/cache.py
BSD-3-Clause
def memoized(maxsize: int = 1024) -> Callable[[_F], _F]: """ Memoization decorator for immutable classes and pure functions. """ def decorator(obj: _F) -> _F: cache: SimpleCache[Hashable, Any] = SimpleCache(maxsize=maxsize) @wraps(obj) def new_callable(*a: Any, **kw: Any) -> An...
Memoization decorator for immutable classes and pure functions.
memoized
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/cache.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/cache.py
BSD-3-Clause
def get_cursor_shape(self, application: Application[Any]) -> CursorShape: """ Return the cursor shape to be used in the current state. """
Return the cursor shape to be used in the current state.
get_cursor_shape
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/cursor_shapes.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/cursor_shapes.py
BSD-3-Clause
def to_cursor_shape_config(value: AnyCursorShapeConfig) -> CursorShapeConfig: """ Take a `CursorShape` instance or `CursorShapeConfig` and turn it into a `CursorShapeConfig`. """ if value is None: return SimpleCursorShapeConfig() if isinstance(value, CursorShape): return SimpleC...
Take a `CursorShape` instance or `CursorShapeConfig` and turn it into a `CursorShapeConfig`.
to_cursor_shape_config
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/cursor_shapes.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/cursor_shapes.py
BSD-3-Clause
def _line_start_indexes(self) -> list[int]: """ Array pointing to the start indexes of all the lines. """ # Cache, because this is often reused. (If it is used, it's often used # many times. And this has to be fast for editing big documents!) if self._cache.line_indexes i...
Array pointing to the start indexes of all the lines.
_line_start_indexes
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def leading_whitespace_in_current_line(self) -> str: """The leading whitespace in the left margin of the current line.""" current_line = self.current_line length = len(current_line) - len(current_line.lstrip()) return current_line[:length]
The leading whitespace in the left margin of the current line.
leading_whitespace_in_current_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def _get_char_relative_to_cursor(self, offset: int = 0) -> str: """ Return character relative to cursor position, or empty string """ try: return self.text[self.cursor_position + offset] except IndexError: return ""
Return character relative to cursor position, or empty string
_get_char_relative_to_cursor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def _find_line_start_index(self, index: int) -> tuple[int, int]: """ For the index of a character at a certain line, calculate the index of the first character on that line. Return (row, index) tuple. """ indexes = self._line_start_indexes pos = bisect.bisect_ri...
For the index of a character at a certain line, calculate the index of the first character on that line. Return (row, index) tuple.
_find_line_start_index
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def translate_index_to_position(self, index: int) -> tuple[int, int]: """ Given an index for the text, return the corresponding (row, col) tuple. (0-based. Returns (0, 0) for index=0.) """ # Find start of this line. row, row_index = self._find_line_start_index(index) ...
Given an index for the text, return the corresponding (row, col) tuple. (0-based. Returns (0, 0) for index=0.)
translate_index_to_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def translate_row_col_to_index(self, row: int, col: int) -> int: """ Given a (row, col) tuple, return the corresponding index. (Row and col params are 0-based.) Negative row/col values are turned into zero. """ try: result = self._line_start_indexes[row] ...
Given a (row, col) tuple, return the corresponding index. (Row and col params are 0-based.) Negative row/col values are turned into zero.
translate_row_col_to_index
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find( self, sub: str, in_current_line: bool = False, include_current_position: bool = False, ignore_case: bool = False, count: int = 1, ) -> int | None: """ Find `text` after the cursor, return position relative to the cursor position. Retu...
Find `text` after the cursor, return position relative to the cursor position. Return `None` if nothing was found. :param count: Find the n-th occurrence.
find
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_all(self, sub: str, ignore_case: bool = False) -> list[int]: """ Find all occurrences of the substring. Return a list of absolute positions in the document. """ flags = re.IGNORECASE if ignore_case else 0 return [a.start() for a in re.finditer(re.escape(sub), sel...
Find all occurrences of the substring. Return a list of absolute positions in the document.
find_all
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_backwards( self, sub: str, in_current_line: bool = False, ignore_case: bool = False, count: int = 1, ) -> int | None: """ Find `text` before the cursor, return position relative to the cursor position. Return `None` if nothing was found. ...
Find `text` before the cursor, return position relative to the cursor position. Return `None` if nothing was found. :param count: Find the n-th occurrence.
find_backwards
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_word_before_cursor( self, WORD: bool = False, pattern: Pattern[str] | None = None ) -> str: """ Give the word before the cursor. If we have whitespace before the cursor this returns an empty string. :param pattern: (None or compiled regex). When given, use this regex...
Give the word before the cursor. If we have whitespace before the cursor this returns an empty string. :param pattern: (None or compiled regex). When given, use this regex pattern.
get_word_before_cursor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_start_of_previous_word( self, count: int = 1, WORD: bool = False, pattern: Pattern[str] | None = None ) -> int | None: """ Return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found. :param pattern:...
Return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found. :param pattern: (None or compiled regex). When given, use this regex pattern.
find_start_of_previous_word
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_boundaries_of_current_word( self, WORD: bool = False, include_leading_whitespace: bool = False, include_trailing_whitespace: bool = False, ) -> tuple[int, int]: """ Return the relative boundaries (startpos, endpos) of the current word under the cursor...
Return the relative boundaries (startpos, endpos) of the current word under the cursor. (This is at the current line, because line boundaries obviously don't belong to any word.) If not on a word, this returns (0,0)
find_boundaries_of_current_word
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_word_under_cursor(self, WORD: bool = False) -> str: """ Return the word, currently below the cursor. This returns an empty string when the cursor is on a whitespace region. """ start, end = self.find_boundaries_of_current_word(WORD=WORD) return self.text[self.curs...
Return the word, currently below the cursor. This returns an empty string when the cursor is on a whitespace region.
get_word_under_cursor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_next_word_beginning( self, count: int = 1, WORD: bool = False ) -> int | None: """ Return an index relative to the cursor position pointing to the start of the next word. Return `None` if nothing was found. """ if count < 0: return self.find_previ...
Return an index relative to the cursor position pointing to the start of the next word. Return `None` if nothing was found.
find_next_word_beginning
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_next_word_ending( self, include_current_position: bool = False, count: int = 1, WORD: bool = False ) -> int | None: """ Return an index relative to the cursor position pointing to the end of the next word. Return `None` if nothing was found. """ if count < 0:...
Return an index relative to the cursor position pointing to the end of the next word. Return `None` if nothing was found.
find_next_word_ending
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_previous_word_beginning( self, count: int = 1, WORD: bool = False ) -> int | None: """ Return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found. """ if count < 0: return self.fi...
Return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found.
find_previous_word_beginning
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_previous_word_ending( self, count: int = 1, WORD: bool = False ) -> int | None: """ Return an index relative to the cursor position pointing to the end of the previous word. Return `None` if nothing was found. """ if count < 0: return self.find_ne...
Return an index relative to the cursor position pointing to the end of the previous word. Return `None` if nothing was found.
find_previous_word_ending
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_next_matching_line( self, match_func: Callable[[str], bool], count: int = 1 ) -> int | None: """ Look downwards for empty lines. Return the line index, relative to the current line. """ result = None for index, line in enumerate(self.lines[self.curso...
Look downwards for empty lines. Return the line index, relative to the current line.
find_next_matching_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_previous_matching_line( self, match_func: Callable[[str], bool], count: int = 1 ) -> int | None: """ Look upwards for empty lines. Return the line index, relative to the current line. """ result = None for index, line in enumerate(self.lines[: self.c...
Look upwards for empty lines. Return the line index, relative to the current line.
find_previous_matching_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_cursor_up_position( self, count: int = 1, preferred_column: int | None = None ) -> int: """ Return the relative cursor position (character index) where we would be if the user pressed the arrow-up button. :param preferred_column: When given, go to this column instead...
Return the relative cursor position (character index) where we would be if the user pressed the arrow-up button. :param preferred_column: When given, go to this column instead of staying at the current column.
get_cursor_up_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_cursor_down_position( self, count: int = 1, preferred_column: int | None = None ) -> int: """ Return the relative cursor position (character index) where we would be if the user pressed the arrow-down button. :param preferred_column: When given, go to this column ins...
Return the relative cursor position (character index) where we would be if the user pressed the arrow-down button. :param preferred_column: When given, go to this column instead of staying at the current column.
get_cursor_down_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_enclosing_bracket_right( self, left_ch: str, right_ch: str, end_pos: int | None = None ) -> int | None: """ Find the right bracket enclosing current position. Return the relative position to the cursor position. When `end_pos` is given, don't look past the position....
Find the right bracket enclosing current position. Return the relative position to the cursor position. When `end_pos` is given, don't look past the position.
find_enclosing_bracket_right
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_enclosing_bracket_left( self, left_ch: str, right_ch: str, start_pos: int | None = None ) -> int | None: """ Find the left bracket enclosing current position. Return the relative position to the cursor position. When `start_pos` is given, don't look past the positio...
Find the left bracket enclosing current position. Return the relative position to the cursor position. When `start_pos` is given, don't look past the position.
find_enclosing_bracket_left
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def find_matching_bracket_position( self, start_pos: int | None = None, end_pos: int | None = None ) -> int: """ Return relative cursor position of matching [, (, { or < bracket. When `start_pos` or `end_pos` are given. Don't look past the positions. """ # Look for ...
Return relative cursor position of matching [, (, { or < bracket. When `start_pos` or `end_pos` are given. Don't look past the positions.
find_matching_bracket_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_start_of_line_position(self, after_whitespace: bool = False) -> int: """Relative position for the start of this line.""" if after_whitespace: current_line = self.current_line return ( len(current_line) - len(current_line.lstrip()) ...
Relative position for the start of this line.
get_start_of_line_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def get_column_cursor_position(self, column: int) -> int: """ Return the relative cursor position for this column at the current line. (It will stay between the boundaries of the line in case of a larger number.) """ line_length = len(self.current_line) current_co...
Return the relative cursor position for this column at the current line. (It will stay between the boundaries of the line in case of a larger number.)
get_column_cursor_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def selection_range( self, ) -> tuple[ int, int ]: # XXX: shouldn't this return `None` if there is no selection??? """ Return (from, to) tuple of the selection. start and end position are included. This doesn't take the selection type into account. Use `...
Return (from, to) tuple of the selection. start and end position are included. This doesn't take the selection type into account. Use `selection_ranges` instead.
selection_range
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def selection_ranges(self) -> Iterable[tuple[int, int]]: """ Return a list of `(from, to)` tuples for the selection or none if nothing was selected. The upper boundary is not included. This will yield several (from, to) tuples in case of a BLOCK selection. This will return zero ...
Return a list of `(from, to)` tuples for the selection or none if nothing was selected. The upper boundary is not included. This will yield several (from, to) tuples in case of a BLOCK selection. This will return zero ranges, like (8,8) for empty lines in a block selection. ...
selection_ranges
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def selection_range_at_line(self, row: int) -> tuple[int, int] | None: """ If the selection spans a portion of the given line, return a (from, to) tuple. The returned upper boundary is not included in the selection, so `(0, 0)` is an empty selection. `(0, 1)`, is a one character select...
If the selection spans a portion of the given line, return a (from, to) tuple. The returned upper boundary is not included in the selection, so `(0, 0)` is an empty selection. `(0, 1)`, is a one character selection. Returns None if the selection doesn't cover this line at all. ...
selection_range_at_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def cut_selection(self) -> tuple[Document, ClipboardData]: """ Return a (:class:`.Document`, :class:`.ClipboardData`) tuple, where the document represents the new document when the selection is cut, and the clipboard data, represents whatever has to be put on the clipboard. """ ...
Return a (:class:`.Document`, :class:`.ClipboardData`) tuple, where the document represents the new document when the selection is cut, and the clipboard data, represents whatever has to be put on the clipboard.
cut_selection
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def paste_clipboard_data( self, data: ClipboardData, paste_mode: PasteMode = PasteMode.EMACS, count: int = 1, ) -> Document: """ Return a new :class:`.Document` instance which contains the result if we would paste this data at the current cursor position. ...
Return a new :class:`.Document` instance which contains the result if we would paste this data at the current cursor position. :param paste_mode: Where to paste. (Before/after/emacs.) :param count: When >1, Paste multiple times.
paste_clipboard_data
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def empty_line_count_at_the_end(self) -> int: """ Return number of empty lines at the end of the document. """ count = 0 for line in self.lines[::-1]: if not line or line.isspace(): count += 1 else: break return cou...
Return number of empty lines at the end of the document.
empty_line_count_at_the_end
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def start_of_paragraph(self, count: int = 1, before: bool = False) -> int: """ Return the start of the current paragraph. (Relative cursor position.) """ def match_func(text: str) -> bool: return not text or text.isspace() line_index = self.find_previous_matching_li...
Return the start of the current paragraph. (Relative cursor position.)
start_of_paragraph
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def end_of_paragraph(self, count: int = 1, after: bool = False) -> int: """ Return the end of the current paragraph. (Relative cursor position.) """ def match_func(text: str) -> bool: return not text or text.isspace() line_index = self.find_next_matching_line(match_...
Return the end of the current paragraph. (Relative cursor position.)
end_of_paragraph
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def insert_after(self, text: str) -> Document: """ Create a new document, with this text inserted after the buffer. It keeps selection ranges and cursor position in sync. """ return Document( text=self.text + text, cursor_position=self.cursor_position, ...
Create a new document, with this text inserted after the buffer. It keeps selection ranges and cursor position in sync.
insert_after
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
def insert_before(self, text: str) -> Document: """ Create a new document, with this text inserted before the buffer. It keeps selection ranges and cursor position in sync. """ selection_state = self.selection if selection_state: selection_state = SelectionSt...
Create a new document, with this text inserted before the buffer. It keeps selection ranges and cursor position in sync.
insert_before
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/document.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/document.py
BSD-3-Clause
async def load(self) -> AsyncGenerator[str, None]: """ Load the history and yield all the entries in reverse order (latest, most recent history entry first). This method can be called multiple times from the `Buffer` to repopulate the history when prompting for a new input. So w...
Load the history and yield all the entries in reverse order (latest, most recent history entry first). This method can be called multiple times from the `Buffer` to repopulate the history when prompting for a new input. So we are responsible here for both caching, and making su...
load
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/history.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/history.py
BSD-3-Clause
def store_string(self, string: str) -> None: """ Store the string in persistent storage. """
Store the string in persistent storage.
store_string
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/history.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/history.py
BSD-3-Clause
async def load(self) -> AsyncGenerator[str, None]: """ Like `History.load(), but call `self.load_history_strings()` in a background thread. """ # Start the load thread, if this is called for the first time. if not self._load_thread: self._load_thread = threadi...
Like `History.load(), but call `self.load_history_strings()` in a background thread.
load
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/history.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/history.py
BSD-3-Clause
def patch_stdout(raw: bool = False) -> Generator[None, None, None]: """ Replace `sys.stdout` by an :class:`_StdoutProxy` instance. Writing to this proxy will make sure that the text appears above the prompt, and that it doesn't destroy the output from the renderer. If no application is curring, th...
Replace `sys.stdout` by an :class:`_StdoutProxy` instance. Writing to this proxy will make sure that the text appears above the prompt, and that it doesn't destroy the output from the renderer. If no application is curring, the behavior should be identical to writing to `sys.stdout` directly. ...
patch_stdout
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/patch_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/patch_stdout.py
BSD-3-Clause
def close(self) -> None: """ Stop `StdoutProxy` proxy. This will terminate the write thread, make sure everything is flushed and wait for the write thread to finish. """ if not self.closed: self._flush_queue.put(_Done()) self._flush_thread.join() ...
Stop `StdoutProxy` proxy. This will terminate the write thread, make sure everything is flushed and wait for the write thread to finish.
close
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/patch_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/patch_stdout.py
BSD-3-Clause
def _get_app_loop(self) -> asyncio.AbstractEventLoop | None: """ Return the event loop for the application currently running in our `AppSession`. """ app = self.app_session.app if app is None: return None return app.loop
Return the event loop for the application currently running in our `AppSession`.
_get_app_loop
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/patch_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/patch_stdout.py
BSD-3-Clause
def _write_and_flush( self, loop: asyncio.AbstractEventLoop | None, text: str ) -> None: """ Write the given text to stdout and flush. If an application is running, use `run_in_terminal`. """ def write_and_flush() -> None: # Ensure that autowrap is enable...
Write the given text to stdout and flush. If an application is running, use `run_in_terminal`.
_write_and_flush
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/patch_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/patch_stdout.py
BSD-3-Clause
def _write(self, data: str) -> None: """ Note: print()-statements cause to multiple write calls. (write('line') and write('\n')). Of course we don't want to call `run_in_terminal` for every individual call, because that's too expensive, and as long as the newlin...
Note: print()-statements cause to multiple write calls. (write('line') and write(' ')). Of course we don't want to call `run_in_terminal` for every individual call, because that's too expensive, and as long as the newline hasn't been written, the text its...
_write
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/patch_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/patch_stdout.py
BSD-3-Clause
def _output_screen_diff( app: Application[Any], output: Output, screen: Screen, current_pos: Point, color_depth: ColorDepth, previous_screen: Screen | None, last_style: str | None, is_done: bool, # XXX: drop is_done full_screen: bool, attrs_for_style_string: _StyleStringToAttrsC...
Render the diff between this screen and the previous screen. This takes two `Screen` instances. The one that represents the output like it was during the last rendering and one that represents the current output raster. Looking at these two `Screen` instances, this function will render the differe...
_output_screen_diff
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def move_cursor(new: Point) -> Point: "Move cursor to this `new` point. Returns the given Point." current_x, current_y = current_pos.x, current_pos.y if new.y > current_y: # Use newlines instead of CURSOR_DOWN, because this might add new lines. # CURSOR_DOWN will never c...
Move cursor to this `new` point. Returns the given Point.
move_cursor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def output_char(char: Char) -> None: """ Write the output of this character. """ nonlocal last_style # If the last printed character has the same style, don't output the # style again. if last_style == char.style: write(char.char) else: ...
Write the output of this character.
output_char
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def get_max_column_index(row: dict[int, Char]) -> int: """ Return max used column index, ignoring whitespace (without style) at the end of the line. This is important for people that copy/paste terminal output. There are two reasons we are sometimes seeing whitespace at the end:...
Return max used column index, ignoring whitespace (without style) at the end of the line. This is important for people that copy/paste terminal output. There are two reasons we are sometimes seeing whitespace at the end: - `BufferControl` adds a trailing space to each line, bec...
get_max_column_index
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def height_is_known(self) -> bool: """ True when the height from the cursor until the bottom of the terminal is known. (It's often nicer to draw bottom toolbars only if the height is known, in order to avoid flickering when the CPR response arrives.) """ if self.full_scre...
True when the height from the cursor until the bottom of the terminal is known. (It's often nicer to draw bottom toolbars only if the height is known, in order to avoid flickering when the CPR response arrives.)
height_is_known
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def rows_above_layout(self) -> int: """ Return the number of rows visible in the terminal above the layout. """ if self._in_alternate_screen: return 0 elif self._min_available_height > 0: total_rows = self.output.get_size().rows last_screen_hei...
Return the number of rows visible in the terminal above the layout.
rows_above_layout
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def request_absolute_cursor_position(self) -> None: """ Get current cursor position. We do this to calculate the minimum available height that we can consume for rendering the prompt. This is the available space below te cursor. For vt100: Do CPR request. (answer will a...
Get current cursor position. We do this to calculate the minimum available height that we can consume for rendering the prompt. This is the available space below te cursor. For vt100: Do CPR request. (answer will arrive later.) For win32: Do API call. (Answer comes imm...
request_absolute_cursor_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def report_absolute_cursor_row(self, row: int) -> None: """ To be called when we know the absolute cursor position. (As an answer of a "Cursor Position Request" response.) """ self.cpr_support = CPR_Support.SUPPORTED # Calculate the amount of rows from the cursor positio...
To be called when we know the absolute cursor position. (As an answer of a "Cursor Position Request" response.)
report_absolute_cursor_row
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def render( self, app: Application[Any], layout: Layout, is_done: bool = False ) -> None: """ Render the current interface to the output. :param is_done: When True, put the cursor at the end of the interface. We won't print any changes to this part. """ ...
Render the current interface to the output. :param is_done: When True, put the cursor at the end of the interface. We won't print any changes to this part.
render
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def erase(self, leave_alternate_screen: bool = True) -> None: """ Hide all output and put the cursor back at the first line. This is for instance used for running a system command (while hiding the CLI) and later resuming the same CLI.) :param leave_alternate_screen: When True, ...
Hide all output and put the cursor back at the first line. This is for instance used for running a system command (while hiding the CLI) and later resuming the same CLI.) :param leave_alternate_screen: When True, and when inside an alternate screen buffer, quit the alternat...
erase
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def print_formatted_text( output: Output, formatted_text: AnyFormattedText, style: BaseStyle, style_transformation: StyleTransformation | None = None, color_depth: ColorDepth | None = None, ) -> None: """ Print a list of (style_str, text) tuples in the given style to the output. """ ...
Print a list of (style_str, text) tuples in the given style to the output.
print_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/renderer.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/renderer.py
BSD-3-Clause
def __invert__(self) -> SearchState: """ Create a new SearchState where backwards becomes forwards and the other way around. """ if self.direction == SearchDirection.BACKWARD: direction = SearchDirection.FORWARD else: direction = SearchDirection.BA...
Create a new SearchState where backwards becomes forwards and the other way around.
__invert__
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