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 write_to_screen( self, screen: Screen, mouse_handlers: MouseHandlers, write_position: WritePosition, parent_style: str, erase_bg: bool, z_index: int | None, ) -> None: """ Render the prompt to a `Screen` instance. :param screen: Th...
Render the prompt to a `Screen` instance. :param screen: The :class:`~prompt_toolkit.layout.screen.Screen` class to which the output has to be written.
write_to_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _divide_heights(self, write_position: WritePosition) -> list[int] | None: """ Return the heights for all rows. Or None when there is not enough space. """ if not self.children: return [] width = write_position.width height = write_position.height ...
Return the heights for all rows. Or None when there is not enough space.
_divide_heights
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _divide_widths(self, width: int) -> list[int] | None: """ Return the widths for all columns. Or None when there is not enough space. """ children = self._all_children if not children: return [] # Calculate widths. dimensions = [c.preferre...
Return the widths for all columns. Or None when there is not enough space.
_divide_widths
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _area_is_empty(self, screen: Screen, write_position: WritePosition) -> bool: """ Return True when the area below the write position is still empty. (For floats that should not hide content underneath.) """ wp = write_position for y in range(wp.ypos, wp.ypos + wp.heig...
Return True when the area below the write position is still empty. (For floats that should not hide content underneath.)
_area_is_empty
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def cursor_position(self) -> Point: """ Return the cursor position coordinates, relative to the left/top corner of the rendered screen. """ cpos = self.ui_content.cursor_position try: y, x = self._rowcol_to_yx[cpos.y, cpos.x] except KeyError: ...
Return the cursor position coordinates, relative to the left/top corner of the rendered screen.
cursor_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def applied_scroll_offsets(self) -> ScrollOffsets: """ Return a :class:`.ScrollOffsets` instance that indicates the actual offset. This can be less than or equal to what's configured. E.g, when the cursor is completely at the top, the top offset will be zero rather than what's co...
Return a :class:`.ScrollOffsets` instance that indicates the actual offset. This can be less than or equal to what's configured. E.g, when the cursor is completely at the top, the top offset will be zero rather than what's configured.
applied_scroll_offsets
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def input_line_to_visible_line(self) -> dict[int, int]: """ Return the dictionary mapping the line numbers of the input buffer to the lines of the screen. When a line spans several rows at the screen, the first row appears in the dictionary. """ result: dict[int, int] = {...
Return the dictionary mapping the line numbers of the input buffer to the lines of the screen. When a line spans several rows at the screen, the first row appears in the dictionary.
input_line_to_visible_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def first_visible_line(self, after_scroll_offset: bool = False) -> int: """ Return the line number (0 based) of the input document that corresponds with the first visible line. """ if after_scroll_offset: return self.displayed_lines[self.applied_scroll_offsets.top] ...
Return the line number (0 based) of the input document that corresponds with the first visible line.
first_visible_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def last_visible_line(self, before_scroll_offset: bool = False) -> int: """ Like `first_visible_line`, but for the last visible line. """ if before_scroll_offset: return self.displayed_lines[-1 - self.applied_scroll_offsets.bottom] else: return self.displa...
Like `first_visible_line`, but for the last visible line.
last_visible_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def center_visible_line( self, before_scroll_offset: bool = False, after_scroll_offset: bool = False ) -> int: """ Like `first_visible_line`, but for the center visible line. """ return ( self.first_visible_line(after_scroll_offset) + ( ...
Like `first_visible_line`, but for the center visible line.
center_visible_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def full_height_visible(self) -> bool: """ True when the full height is visible (There is no vertical scroll.) """ return ( self.vertical_scroll == 0 and self.last_visible_line() == self.content_height )
True when the full height is visible (There is no vertical scroll.)
full_height_visible
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def vertical_scroll_percentage(self) -> int: """ Vertical scroll as a percentage. (0 means: the top is visible, 100 means: the bottom is visible.) """ if self.bottom_visible: return 100 else: return 100 * self.vertical_scroll // self.content_height
Vertical scroll as a percentage. (0 means: the top is visible, 100 means: the bottom is visible.)
vertical_scroll_percentage
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def get_height_for_line(self, lineno: int) -> int: """ Return the height of the given line. (The height that it would take, if this line became visible.) """ if self.wrap_lines: return self.ui_content.get_height_for_line( lineno, self.window_width, sel...
Return the height of the given line. (The height that it would take, if this line became visible.)
get_height_for_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _get_margin_width(self, margin: Margin) -> int: """ Return the width for this margin. (Calculate only once per render time.) """ # Margin.get_width, needs to have a UIContent instance. def get_ui_content() -> UIContent: return self._get_ui_content(width=0...
Return the width for this margin. (Calculate only once per render time.)
_get_margin_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _get_total_margin_width(self) -> int: """ Calculate and return the width of the margin (left + right). """ return sum(self._get_margin_width(m) for m in self.left_margins) + sum( self._get_margin_width(m) for m in self.right_margins )
Calculate and return the width of the margin (left + right).
_get_total_margin_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def preferred_width(self, max_available_width: int) -> Dimension: """ Calculate the preferred width for this window. """ def preferred_content_width() -> int | None: """Content width: is only calculated if no exact width for the window was given.""" i...
Calculate the preferred width for this window.
preferred_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def preferred_content_width() -> int | None: """Content width: is only calculated if no exact width for the window was given.""" if self.ignore_content_width(): return None # Calculate the width of the margin. total_margin_width = self._get_to...
Content width: is only calculated if no exact width for the window was given.
preferred_content_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def preferred_height(self, width: int, max_available_height: int) -> Dimension: """ Calculate the preferred height for this window. """ def preferred_content_height() -> int | None: """Content height: is only calculated if no exact height for the window was given...
Calculate the preferred height for this window.
preferred_height
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def preferred_content_height() -> int | None: """Content height: is only calculated if no exact height for the window was given.""" if self.ignore_content_height(): return None total_margin_width = self._get_total_margin_width() wrap_lines = s...
Content height: is only calculated if no exact height for the window was given.
preferred_content_height
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _merge_dimensions( dimension: Dimension | None, get_preferred: Callable[[], int | None], dont_extend: bool = False, ) -> Dimension: """ Take the Dimension from this `Window` class and the received preferred size from the `UIControl` and return a `Dimension` to rep...
Take the Dimension from this `Window` class and the received preferred size from the `UIControl` and return a `Dimension` to report to the parent container.
_merge_dimensions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _get_digraph_char(self) -> str | None: "Return `False`, or the Digraph symbol to be used." app = get_app() if app.quoted_insert: return "^" if app.vi_state.waiting_for_digraph: if app.vi_state.digraph_symbol1: return app.vi_state.digraph_symbol...
Return `False`, or the Digraph symbol to be used.
_get_digraph_char
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def write_to_screen( self, screen: Screen, mouse_handlers: MouseHandlers, write_position: WritePosition, parent_style: str, erase_bg: bool, z_index: int | None, ) -> None: """ Write window to screen. This renders the user control, the margins a...
Write window to screen. This renders the user control, the margins and copies everything over to the absolute position at the given screen.
write_to_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def mouse_handler(mouse_event: MouseEvent) -> NotImplementedOrNone: """ Wrapper around the mouse_handler of the `UIControl` that turns screen coordinates into line coordinates. Returns `NotImplemented` if no UI invalidation should be done. """ # Do...
Wrapper around the mouse_handler of the `UIControl` that turns screen coordinates into line coordinates. Returns `NotImplemented` if no UI invalidation should be done.
mouse_handler
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _copy_body( self, ui_content: UIContent, new_screen: Screen, write_position: WritePosition, move_x: int, width: int, vertical_scroll: int = 0, horizontal_scroll: int = 0, wrap_lines: bool = False, highlight_lines: bool = False, ...
Copy the UIContent into the output screen. Return (visible_line_to_row_col, rowcol_to_yx) tuple. :param get_line_prefix: None or a callable that takes a line number (int) and a wrap_count (int) and returns formatted text.
_copy_body
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def copy_line( line: StyleAndTextTuples, lineno: int, x: int, y: int, is_input: bool = False, ) -> tuple[int, int]: """ Copy over a single line to the output screen. This can wrap over multiple lines in the output. I...
Copy over a single line to the output screen. This can wrap over multiple lines in the output. It will call the prefix (prompt) function before every line.
copy_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def cursor_pos_to_screen_pos(row: int, col: int) -> Point: "Translate row/col from UIContent to real Screen coordinates." try: y, x = rowcol_to_yx[row, col] except KeyError: # Normally this should never happen. (It is a bug, if it happens.) ...
Translate row/col from UIContent to real Screen coordinates.
cursor_pos_to_screen_pos
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _fill_bg( self, screen: Screen, write_position: WritePosition, erase_bg: bool ) -> None: """ Erase/fill the background. (Useful for floats and when a `char` has been given.) """ char: str | None if callable(self.char): char = self.char() ...
Erase/fill the background. (Useful for floats and when a `char` has been given.)
_fill_bg
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _highlight_digraph(self, new_screen: Screen) -> None: """ When we are in Vi digraph mode, put a question mark underneath the cursor. """ digraph_char = self._get_digraph_char() if digraph_char: cpos = new_screen.get_cursor_position(self) new_sc...
When we are in Vi digraph mode, put a question mark underneath the cursor.
_highlight_digraph
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _show_key_processor_key_buffer(self, new_screen: Screen) -> None: """ When the user is typing a key binding that consists of several keys, display the last pressed key if the user is in insert mode and the key is meaningful to be displayed. E.g. Some people want to bind 'jj' ...
When the user is typing a key binding that consists of several keys, display the last pressed key if the user is in insert mode and the key is meaningful to be displayed. E.g. Some people want to bind 'jj' to escape in Vi insert mode. But the first 'j' needs to be displayed...
_show_key_processor_key_buffer
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _copy_margin( self, margin_content: UIContent, new_screen: Screen, write_position: WritePosition, move_x: int, width: int, ) -> None: """ Copy characters from the margin screen to the real screen. """ xpos = write_position.xpos + mo...
Copy characters from the margin screen to the real screen.
_copy_margin
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _scroll(self, ui_content: UIContent, width: int, height: int) -> None: """ Scroll body. Ensure that the cursor is visible. """ if self.wrap_lines(): func = self._scroll_when_linewrapping else: func = self._scroll_without_linewrapping func(ui_c...
Scroll body. Ensure that the cursor is visible.
_scroll
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _scroll_when_linewrapping( self, ui_content: UIContent, width: int, height: int ) -> None: """ Scroll to make sure the cursor position is visible and that we maintain the requested scroll offset. Set `self.horizontal_scroll/vertical_scroll`. """ scroll_of...
Scroll to make sure the cursor position is visible and that we maintain the requested scroll offset. Set `self.horizontal_scroll/vertical_scroll`.
_scroll_when_linewrapping
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def get_topmost_visible() -> int: """ Calculate the upper most line that can be visible, while the bottom is still visible. We should not allow scroll more than this if `allow_scroll_beyond_bottom` is false. """ prev_lineno = ui_content.line_count ...
Calculate the upper most line that can be visible, while the bottom is still visible. We should not allow scroll more than this if `allow_scroll_beyond_bottom` is false.
get_topmost_visible
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def do_scroll( current_scroll: int, scroll_offset_start: int, scroll_offset_end: int, cursor_pos: int, window_size: int, content_size: int, ) -> int: "Scrolling algorithm. Used for both horizontal and vertical scrolling." ...
Scrolling algorithm. Used for both horizontal and vertical scrolling.
do_scroll
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def _mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone: """ Mouse handler. Called when the UI control doesn't handle this particular event. Return `NotImplemented` if nothing was done as a consequence of this key binding (no UI invalidate required in that case...
Mouse handler. Called when the UI control doesn't handle this particular event. Return `NotImplemented` if nothing was done as a consequence of this key binding (no UI invalidate required in that case).
_mouse_handler
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def to_container(container: AnyContainer) -> Container: """ Make sure that the given object is a :class:`.Container`. """ if isinstance(container, Container): return container elif hasattr(container, "__pt_container__"): return to_container(container.__pt_container__()) else: ...
Make sure that the given object is a :class:`.Container`.
to_container
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def to_window(container: AnyContainer) -> Window: """ Make sure that the given argument is a :class:`.Window`. """ if isinstance(container, Window): return container elif hasattr(container, "__pt_container__"): return to_window(cast("MagicContainer", container).__pt_container__()) ...
Make sure that the given argument is a :class:`.Window`.
to_window
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def is_container(value: object) -> TypeGuard[AnyContainer]: """ Checks whether the given value is a container object (for use in assert statements). """ if isinstance(value, Container): return True if hasattr(value, "__pt_container__"): return is_container(cast("MagicContainer", ...
Checks whether the given value is a container object (for use in assert statements).
is_container
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/containers.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/containers.py
BSD-3-Clause
def create_content(self, width: int, height: int) -> UIContent: """ Generate the content for this user control. Returns a :class:`.UIContent` instance. """
Generate the content for this user control. Returns a :class:`.UIContent` instance.
create_content
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def move_cursor_down(self) -> None: """ Request to move the cursor down. This happens when scrolling down and the cursor is completely at the top. """
Request to move the cursor down. This happens when scrolling down and the cursor is completely at the top.
move_cursor_down
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def move_cursor_up(self) -> None: """ Request to move the cursor up. """
Request to move the cursor up.
move_cursor_up
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def get_key_bindings(self) -> KeyBindingsBase | None: """ The key bindings that are specific for this user control. Return a :class:`.KeyBindings` object if some key bindings are specified, or `None` otherwise. """
The key bindings that are specific for this user control. Return a :class:`.KeyBindings` object if some key bindings are specified, or `None` otherwise.
get_key_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def __getitem__(self, lineno: int) -> StyleAndTextTuples: "Make it iterable (iterate line by line)." if lineno < self.line_count: return self.get_line(lineno) else: raise IndexError
Make it iterable (iterate line by line).
__getitem__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def get_height_for_line( self, lineno: int, width: int, get_line_prefix: GetLinePrefixCallable | None, slice_stop: int | None = None, ) -> int: """ Return the height that a given line would need if it is rendered in a space with the given width (using ...
Return the height that a given line would need if it is rendered in a space with the given width (using line wrapping). :param get_line_prefix: None or a `Window.get_line_prefix` callable that returns the prefix to be inserted before this line. :param slice_stop: Wrap only ...
get_height_for_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def _get_formatted_text_cached(self) -> StyleAndTextTuples: """ Get fragments, but only retrieve fragments once during one render run. (This function is called several times during one rendering, because we also need those for calculating the dimensions.) """ return self....
Get fragments, but only retrieve fragments once during one render run. (This function is called several times during one rendering, because we also need those for calculating the dimensions.)
_get_formatted_text_cached
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def preferred_width(self, max_available_width: int) -> int: """ Return the preferred width for this control. That is the width of the longest line. """ text = fragment_list_to_text(self._get_formatted_text_cached()) line_lengths = [get_cwidth(l) for l in text.split("\n")]...
Return the preferred width for this control. That is the width of the longest line.
preferred_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def preferred_height( self, width: int, max_available_height: int, wrap_lines: bool, get_line_prefix: GetLinePrefixCallable | None, ) -> int | None: """ Return the preferred height for this control. """ content = self.create_content(width, None...
Return the preferred height for this control.
preferred_height
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone: """ Handle mouse events. (When the fragment list contained mouse handlers and the user clicked on on any of these, the matching handler is called. This handler can still return `NotImplemented` in case we ...
Handle mouse events. (When the fragment list contained mouse handlers and the user clicked on on any of these, the matching handler is called. This handler can still return `NotImplemented` in case we want the :class:`~prompt_toolkit.layout.Window` to handle this particular ...
mouse_handler
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def search_state(self) -> SearchState: """ Return the `SearchState` for searching this `BufferControl`. This is always associated with the search control. If one search bar is used for searching multiple `BufferControls`, then they share the same `SearchState`. """ ...
Return the `SearchState` for searching this `BufferControl`. This is always associated with the search control. If one search bar is used for searching multiple `BufferControls`, then they share the same `SearchState`.
search_state
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def _get_formatted_text_for_line_func( self, document: Document ) -> Callable[[int], StyleAndTextTuples]: """ Create a function that returns the fragments for a given line. """ # Cache using `document.text`. def get_formatted_text_for_line() -> Callable[[int], StyleA...
Create a function that returns the fragments for a given line.
_get_formatted_text_for_line_func
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def _create_get_processed_line_func( self, document: Document, width: int, height: int ) -> Callable[[int], _ProcessedLine]: """ Create a function that takes a line number of the current document and returns a _ProcessedLine(processed_fragments, source_to_display, display_to_source) ...
Create a function that takes a line number of the current document and returns a _ProcessedLine(processed_fragments, source_to_display, display_to_source) tuple.
_create_get_processed_line_func
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def transform( lineno: int, fragments: StyleAndTextTuples, get_line: Callable[[int], StyleAndTextTuples], ) -> _ProcessedLine: "Transform the fragments for a given line number." # Get cursor position at this line. def source_to_display(i: ...
Transform the fragments for a given line number.
transform
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def translate_rowcol(row: int, col: int) -> Point: "Return the content column for this coordinate." return Point(x=get_processed_line(row).source_to_display(col), y=row)
Return the content column for this coordinate.
translate_rowcol
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def get_line(i: int) -> StyleAndTextTuples: "Return the fragments for a given line number." fragments = get_processed_line(i).fragments # Add a space at the end, because that is a possible cursor # position. (When inserting after the input.) We should do this on ...
Return the fragments for a given line number.
get_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/controls.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/controls.py
BSD-3-Clause
def is_zero(self) -> bool: "True if this `Dimension` represents a zero size." return self.preferred == 0 or self.max == 0
True if this `Dimension` represents a zero size.
is_zero
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dimension.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dimension.py
BSD-3-Clause
def sum_layout_dimensions(dimensions: list[Dimension]) -> Dimension: """ Sum a list of :class:`.Dimension` instances. """ min = sum(d.min for d in dimensions) max = sum(d.max for d in dimensions) preferred = sum(d.preferred for d in dimensions) return Dimension(min=min, max=max, preferred=p...
Sum a list of :class:`.Dimension` instances.
sum_layout_dimensions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dimension.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dimension.py
BSD-3-Clause
def max_layout_dimensions(dimensions: list[Dimension]) -> Dimension: """ Take the maximum of a list of :class:`.Dimension` instances. Used when we have a HSplit/VSplit, and we want to get the best width/height.) """ if not len(dimensions): return Dimension.zero() # If all dimensions are...
Take the maximum of a list of :class:`.Dimension` instances. Used when we have a HSplit/VSplit, and we want to get the best width/height.)
max_layout_dimensions
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dimension.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dimension.py
BSD-3-Clause
def to_dimension(value: AnyDimension) -> Dimension: """ Turn the given object into a `Dimension` object. """ if value is None: return Dimension() if isinstance(value, int): return Dimension.exact(value) if isinstance(value, Dimension): return value if callable(value):...
Turn the given object into a `Dimension` object.
to_dimension
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dimension.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dimension.py
BSD-3-Clause
def is_dimension(value: object) -> TypeGuard[AnyDimension]: """ Test whether the given value could be a valid dimension. (For usage in an assertion. It's not guaranteed in case of a callable.) """ if value is None: return True if callable(value): return True # Assume it's a call...
Test whether the given value could be a valid dimension. (For usage in an assertion. It's not guaranteed in case of a callable.)
is_dimension
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dimension.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dimension.py
BSD-3-Clause
def create_dummy_layout() -> Layout: """ Create a dummy layout for use in an 'Application' that doesn't have a layout specified. When ENTER is pressed, the application quits. """ kb = KeyBindings() @kb.add("enter") def enter(event: E) -> None: event.app.exit() control = Formatt...
Create a dummy layout for use in an 'Application' that doesn't have a layout specified. When ENTER is pressed, the application quits.
create_dummy_layout
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/dummy.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/dummy.py
BSD-3-Clause
def find_all_windows(self) -> Generator[Window, None, None]: """ Find all the :class:`.UIControl` objects in this layout. """ for item in self.walk(): if isinstance(item, Window): yield item
Find all the :class:`.UIControl` objects in this layout.
find_all_windows
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def focus(self, value: FocusableElement) -> None: """ Focus the given UI element. `value` can be either: - a :class:`.UIControl` - a :class:`.Buffer` instance or the name of a :class:`.Buffer` - a :class:`.Window` - Any container object. In this case we will foc...
Focus the given UI element. `value` can be either: - a :class:`.UIControl` - a :class:`.Buffer` instance or the name of a :class:`.Buffer` - a :class:`.Window` - Any container object. In this case we will focus the :class:`.Window` from this container that wa...
focus
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def has_focus(self, value: FocusableElement) -> bool: """ Check whether the given control has the focus. :param value: :class:`.UIControl` or :class:`.Window` instance. """ if isinstance(value, str): if self.current_buffer is None: return False ...
Check whether the given control has the focus. :param value: :class:`.UIControl` or :class:`.Window` instance.
has_focus
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def current_control(self, control: UIControl) -> None: """ Set the :class:`.UIControl` to receive the focus. """ for window in self.find_all_windows(): if window.content == control: self.current_window = window return raise ValueError(...
Set the :class:`.UIControl` to receive the focus.
current_control
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def is_searching(self) -> bool: "True if we are searching right now." return self.current_control in self.search_links
True if we are searching right now.
is_searching
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def search_target_buffer_control(self) -> BufferControl | None: """ Return the :class:`.BufferControl` in which we are searching or `None`. """ # Not every `UIControl` is a `BufferControl`. This only applies to # `BufferControl`. control = self.current_control if...
Return the :class:`.BufferControl` in which we are searching or `None`.
search_target_buffer_control
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def get_focusable_windows(self) -> Iterable[Window]: """ Return all the :class:`.Window` objects which are focusable (in the 'modal' area). """ for w in self.walk_through_modal_area(): if isinstance(w, Window) and w.content.is_focusable(): yield w
Return all the :class:`.Window` objects which are focusable (in the 'modal' area).
get_focusable_windows
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def get_visible_focusable_windows(self) -> list[Window]: """ Return a list of :class:`.Window` objects that are focusable. """ # focusable windows are windows that are visible, but also part of the # modal container. Make sure to keep the ordering. visible_windows = self....
Return a list of :class:`.Window` objects that are focusable.
get_visible_focusable_windows
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def current_buffer(self) -> Buffer | None: """ The currently focused :class:`~.Buffer` or `None`. """ ui_control = self.current_control if isinstance(ui_control, BufferControl): return ui_control.buffer return None
The currently focused :class:`~.Buffer` or `None`.
current_buffer
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def get_buffer_by_name(self, buffer_name: str) -> Buffer | None: """ Look in the layout for a buffer with the given name. Return `None` when nothing was found. """ for w in self.walk(): if isinstance(w, Window) and isinstance(w.content, BufferControl): ...
Look in the layout for a buffer with the given name. Return `None` when nothing was found.
get_buffer_by_name
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def buffer_has_focus(self) -> bool: """ Return `True` if the currently focused control is a :class:`.BufferControl`. (For instance, used to determine whether the default key bindings should be active or not.) """ ui_control = self.current_control return isinstance...
Return `True` if the currently focused control is a :class:`.BufferControl`. (For instance, used to determine whether the default key bindings should be active or not.)
buffer_has_focus
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def previous_control(self) -> UIControl: """ Get the :class:`.UIControl` to previously had the focus. """ try: return self._stack[-2].content except IndexError: return self._stack[-1].content
Get the :class:`.UIControl` to previously had the focus.
previous_control
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def focus_last(self) -> None: """ Give the focus to the last focused control. """ if len(self._stack) > 1: self._stack = self._stack[:-1]
Give the focus to the last focused control.
focus_last
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def focus_next(self) -> None: """ Focus the next visible/focusable Window. """ windows = self.get_visible_focusable_windows() if len(windows) > 0: try: index = windows.index(self.current_window) except ValueError: index = 0...
Focus the next visible/focusable Window.
focus_next
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def focus_previous(self) -> None: """ Focus the previous visible/focusable Window. """ windows = self.get_visible_focusable_windows() if len(windows) > 0: try: index = windows.index(self.current_window) except ValueError: i...
Focus the previous visible/focusable Window.
focus_previous
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def walk_through_modal_area(self) -> Iterable[Container]: """ Walk through all the containers which are in the current 'modal' part of the layout. """ # Go up in the tree, and find the root. (it will be a part of the # layout, if the focus is in a modal part.) roo...
Walk through all the containers which are in the current 'modal' part of the layout.
walk_through_modal_area
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def get_parent(self, container: Container) -> Container | None: """ Return the parent container for the given container, or ``None``, if it wasn't found. """ try: return self._child_to_parent[container] except KeyError: return None
Return the parent container for the given container, or ``None``, if it wasn't found.
get_parent
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def walk(container: Container, skip_hidden: bool = False) -> Iterable[Container]: """ Walk through layout, starting at this container. """ # When `skip_hidden` is set, don't go into disabled ConditionalContainer containers. if ( skip_hidden and isinstance(container, ConditionalContai...
Walk through layout, starting at this container.
walk
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/layout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/layout.py
BSD-3-Clause
def create_margin( self, window_render_info: WindowRenderInfo, width: int, height: int ) -> StyleAndTextTuples: """ Creates a margin. This should return a list of (style_str, text) tuples. :param window_render_info: :class:`~prompt_toolkit.layout.containers.Windo...
Creates a margin. This should return a list of (style_str, text) tuples. :param window_render_info: :class:`~prompt_toolkit.layout.containers.WindowRenderInfo` instance, generated after rendering and copying the visible part of the :class:`~prompt_toolkit.la...
create_margin
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/margins.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/margins.py
BSD-3-Clause
def is_scroll_button(row: int) -> bool: "True if we should display a button on this row." return scrollbar_top <= row <= scrollbar_top + scrollbar_height
True if we should display a button on this row.
is_scroll_button
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/margins.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/margins.py
BSD-3-Clause
def get_width(self, get_ui_content: Callable[[], UIContent]) -> int: "Width to report to the `Window`." # Take the width from the first line. text = fragment_list_to_text(self.get_prompt()) return get_cwidth(text)
Width to report to the `Window`.
get_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/margins.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/margins.py
BSD-3-Clause
def create_content(self, width: int, height: int) -> UIContent: """ Create a UIContent object for this control. """ complete_state = get_app().current_buffer.complete_state if complete_state: completions = complete_state.completions index = complete_state....
Create a UIContent object for this control.
create_content
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def _get_menu_width(self, max_width: int, complete_state: CompletionState) -> int: """ Return the width of the main column. """ return min( max_width, max( self.MIN_WIDTH, max(get_cwidth(c.display_text) for c in complete_state.compl...
Return the width of the main column.
_get_menu_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def _get_menu_meta_width( self, max_width: int, complete_state: CompletionState ) -> int: """ Return the width of the meta column. """ def meta_width(completion: Completion) -> int: return get_cwidth(completion.display_meta_text) if self._show_meta(compl...
Return the width of the meta column.
_get_menu_meta_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone: """ Handle mouse events: clicking and scrolling. """ b = get_app().current_buffer if mouse_event.event_type == MouseEventType.MOUSE_UP: # Select completion. b.go_to_completion(mouse...
Handle mouse events: clicking and scrolling.
mouse_handler
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def _get_menu_item_fragments( completion: Completion, is_current_completion: bool, width: int, space_after: bool = False, ) -> StyleAndTextTuples: """ Get the style/text tuples for a menu item, styled and trimmed to the given width. """ if is_current_completion: style_str = f...
Get the style/text tuples for a menu item, styled and trimmed to the given width.
_get_menu_item_fragments
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def _trim_formatted_text( formatted_text: StyleAndTextTuples, max_width: int ) -> tuple[StyleAndTextTuples, int]: """ Trim the text to `max_width`, append dots when the text is too long. Returns (text, width) tuple. """ width = fragment_list_width(formatted_text) # When the text is too wide...
Trim the text to `max_width`, append dots when the text is too long. Returns (text, width) tuple.
_trim_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def preferred_width(self, max_available_width: int) -> int | None: """ Preferred width: prefer to use at least min_rows, but otherwise as much as possible horizontally. """ complete_state = get_app().current_buffer.complete_state if complete_state is None: ret...
Preferred width: prefer to use at least min_rows, but otherwise as much as possible horizontally.
preferred_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def preferred_height( self, width: int, max_available_height: int, wrap_lines: bool, get_line_prefix: GetLinePrefixCallable | None, ) -> int | None: """ Preferred height: as much as needed in order to display all the completions. """ complete_s...
Preferred height: as much as needed in order to display all the completions.
preferred_height
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def create_content(self, width: int, height: int) -> UIContent: """ Create a UIContent object for this menu. """ complete_state = get_app().current_buffer.complete_state if complete_state is None: return UIContent() column_width = self._get_column_width(compl...
Create a UIContent object for this menu.
create_content
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def is_current_completion(completion: Completion) -> bool: "Returns True when this completion is the currently selected one." return ( complete_state is not None and complete_state.complete_index is not None and c == complete_state.current_completi...
Returns True when this completion is the currently selected one.
is_current_completion
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def _get_column_width(self, completion_state: CompletionState) -> int: """ Return the width of each column. """ try: count, width = self._column_width_for_completion_state[completion_state] if count != len(completion_state.completions): # Number of...
Return the width of each column.
_get_column_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def get_key_bindings(self) -> KeyBindings: """ Expose key bindings that handle the left/right arrow keys when the menu is displayed. """ from prompt_toolkit.key_binding.key_bindings import KeyBindings kb = KeyBindings() @Condition def filter() -> bool: ...
Expose key bindings that handle the left/right arrow keys when the menu is displayed.
get_key_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def filter() -> bool: "Only handle key bindings if this menu is visible." app = get_app() complete_state = app.current_buffer.complete_state # There need to be completions, and one needs to be selected. if complete_state is None or complete_state.complete_ind...
Only handle key bindings if this menu is visible.
filter
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def preferred_width(self, max_available_width: int) -> int | None: """ Report the width of the longest meta text as the preferred width of this control. It could be that we use less width, but this way, we're sure that the layout doesn't change when we select another completion (E.g. th...
Report the width of the longest meta text as the preferred width of this control. It could be that we use less width, but this way, we're sure that the layout doesn't change when we select another completion (E.g. that completions are suddenly shown in more or fewer columns.)
preferred_width
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/menus.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/menus.py
BSD-3-Clause
def apply_transformation( self, transformation_input: TransformationInput ) -> Transformation: """ Apply transformation. Returns a :class:`.Transformation` instance. :param transformation_input: :class:`.TransformationInput` object. """ return Transformation(transfor...
Apply transformation. Returns a :class:`.Transformation` instance. :param transformation_input: :class:`.TransformationInput` object.
apply_transformation
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/processors.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/processors.py
BSD-3-Clause
def _get_search_text(self, buffer_control: BufferControl) -> str: """ The text we are searching for. """ # When the search buffer has focus, take that text. search_buffer = buffer_control.search_buffer if search_buffer is not None and search_buffer.text: retur...
The text we are searching for.
_get_search_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/processors.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/processors.py
BSD-3-Clause
def _get_positions_to_highlight(self, document: Document) -> list[tuple[int, int]]: """ Return a list of (row, col) tuples that need to be highlighted. """ pos: int | None # Try for the character under the cursor. if document.current_char and document.current_char in sel...
Return a list of (row, col) tuples that need to be highlighted.
_get_positions_to_highlight
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/processors.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/processors.py
BSD-3-Clause
def display_to_source(display_pos: int) -> int: "Maps display cursor position to the original one." position_mappings_reversed = {v: k for k, v in position_mappings.items()} while display_pos >= 0: try: return position_mappings_reversed[display_po...
Maps display cursor position to the original one.
display_to_source
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/processors.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/processors.py
BSD-3-Clause
def filter_processor(item: Processor) -> Processor | None: """Filter processors from the main control that we want to disable here. This returns either an accepted processor or None.""" # For a `_MergedProcessor`, check each individual processor, recursively. if isinstanc...
Filter processors from the main control that we want to disable here. This returns either an accepted processor or None.
filter_processor
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/processors.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/processors.py
BSD-3-Clause