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 merge_processors(processors: list[Processor]) -> Processor: """ Merge multiple `Processor` objects into one. """ if len(processors) == 0: return DummyProcessor() if len(processors) == 1: return processors[0] # Nothing to merge. return _MergedProcessor(processors)
Merge multiple `Processor` objects into one.
merge_processors
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 source_to_display(i: int) -> int: """Translate x position from the buffer to the x position in the processor fragments list.""" for f in source_to_display_functions: i = f(i) return i
Translate x position from the buffer to the x position in the processor fragments list.
source_to_display
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_cursor_position(self, window: Window) -> Point: """ Get the cursor position for a given window. Returns a `Point`. """ try: return self.cursor_positions[window] except KeyError: return Point(x=0, y=0)
Get the cursor position for a given window. Returns a `Point`.
get_cursor_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/screen.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/screen.py
BSD-3-Clause
def get_menu_position(self, window: Window) -> Point: """ Get the menu position for a given window. (This falls back to the cursor position if no menu position was set.) """ try: return self.menu_positions[window] except KeyError: try: ...
Get the menu position for a given window. (This falls back to the cursor position if no menu position was set.)
get_menu_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/screen.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/screen.py
BSD-3-Clause
def draw_all_floats(self) -> None: """ Draw all float functions in order of z-index. """ # We keep looping because some draw functions could add new functions # to this list. See `FloatContainer`. while self._draw_float_functions: # Sort the floats that we hav...
Draw all float functions in order of z-index.
draw_all_floats
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/screen.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/screen.py
BSD-3-Clause
def append_style_to_content(self, style_str: str) -> None: """ For all the characters in the screen. Set the style string to the given `style_str`. """ b = self.data_buffer char_cache = _CHAR_CACHE append_style = " " + style_str for y, row in b.items(): ...
For all the characters in the screen. Set the style string to the given `style_str`.
append_style_to_content
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/screen.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/screen.py
BSD-3-Clause
def fill_area( self, write_position: WritePosition, style: str = "", after: bool = False ) -> None: """ Fill the content of this area, using the given `style`. The style is prepended before whatever was here before. """ if not style.strip(): return ...
Fill the content of this area, using the given `style`. The style is prepended before whatever was here before.
fill_area
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/screen.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/screen.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: """ Render scrollable pane content. This works by rendering on ...
Render scrollable pane content. This works by rendering on an off-screen canvas, and copying over the visible region.
write_to_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def _clip_point_to_visible_area( self, point: Point, write_position: WritePosition ) -> Point: """ Ensure that the cursor and menu positions always are always reported """ if point.x < write_position.xpos: point = point._replace(x=write_position.xpos) if p...
Ensure that the cursor and menu positions always are always reported
_clip_point_to_visible_area
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def _copy_over_screen( self, screen: Screen, temp_screen: Screen, write_position: WritePosition, virtual_width: int, ) -> None: """ Copy over visible screen content and "zero width escape sequences". """ ypos = write_position.ypos xpos ...
Copy over visible screen content and "zero width escape sequences".
_copy_over_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def _copy_over_mouse_handlers( self, mouse_handlers: MouseHandlers, temp_mouse_handlers: MouseHandlers, write_position: WritePosition, virtual_width: int, ) -> None: """ Copy over mouse handlers from virtual screen to real screen. Note: we take `virtu...
Copy over mouse handlers from virtual screen to real screen. Note: we take `virtual_width` because we don't want to copy over mouse handlers that we possibly have behind the scrollbar.
_copy_over_mouse_handlers
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def wrap_mouse_handler(handler: MouseHandler) -> MouseHandler: "Wrap mouse handler. Translate coordinates in `MouseEvent`." if handler not in mouse_handler_wrappers: def new_handler(event: MouseEvent) -> None: new_event = MouseEvent( p...
Wrap mouse handler. Translate coordinates in `MouseEvent`.
wrap_mouse_handler
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def _make_window_visible( self, visible_height: int, virtual_height: int, visible_win_write_pos: WritePosition, cursor_position: Point | None, ) -> None: """ Scroll the scrollable pane, so that this window becomes visible. :param visible_height: Heigh...
Scroll the scrollable pane, so that this window becomes visible. :param visible_height: Height of this `ScrollablePane` that is rendered. :param virtual_height: Height of the virtual, temp screen. :param visible_win_write_pos: `WritePosition` of the nested window on the tem...
_make_window_visible
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def _draw_scrollbar( self, write_position: WritePosition, content_height: int, screen: Screen ) -> None: """ Draw the scrollbar on the screen. Note: There is some code duplication with the `ScrollbarMargin` implementation. """ window_height = write_pos...
Draw the scrollbar on the screen. Note: There is some code duplication with the `ScrollbarMargin` implementation.
_draw_scrollbar
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/scrollable_pane.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/scrollable_pane.py
BSD-3-Clause
def __setitem__( self, index: SupportsIndex | slice, value: _T | Iterable[_T] ) -> None: """ Ensure that when `(style_str, 'long string')` is set, the string will be exploded. """ if not isinstance(index, slice): int_index = index.__index__() i...
Ensure that when `(style_str, 'long string')` is set, the string will be exploded.
__setitem__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/utils.py
BSD-3-Clause
def explode_text_fragments(fragments: Iterable[_T]) -> _ExplodedList[_T]: """ Turn a list of (style_str, text) tuples into another list where each string is exactly one character. It should be fine to call this function several times. Calling this on a list that is already exploded, is a null opera...
Turn a list of (style_str, text) tuples into another list where each string is exactly one character. It should be fine to call this function several times. Calling this on a list that is already exploded, is a null operation. :param fragments: List of (style, text) tuples.
explode_text_fragments
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/layout/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/layout/utils.py
BSD-3-Clause
def lex_document(self, document: Document) -> Callable[[int], StyleAndTextTuples]: """ Takes a :class:`~prompt_toolkit.document.Document` and returns a callable that takes a line number and returns a list of ``(style_str, text)`` tuples for that line. XXX: Note that in the past,...
Takes a :class:`~prompt_toolkit.document.Document` and returns a callable that takes a line number and returns a list of ``(style_str, text)`` tuples for that line. XXX: Note that in the past, this was supposed to return a list of ``(Token, text)`` tuples, just like a Pygm...
lex_document
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/base.py
BSD-3-Clause
def get_line(lineno: int) -> StyleAndTextTuples: "Return the tokens for the given line." try: return [(self.style, lines[lineno])] except IndexError: return []
Return the tokens for the given line.
get_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/base.py
BSD-3-Clause
def get_sync_start_position( self, document: Document, lineno: int ) -> tuple[int, int]: """ Return the position from where we can start lexing as a (row, column) tuple. :param document: `Document` instance that contains all the lines. :param lineno: The line that we...
Return the position from where we can start lexing as a (row, column) tuple. :param document: `Document` instance that contains all the lines. :param lineno: The line that we want to highlight. (We need to return this line, or an earlier position.)
get_sync_start_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def get_sync_start_position( self, document: Document, lineno: int ) -> tuple[int, int]: """ Scan backwards, and find a possible position to start. """ pattern = self._compiled_pattern lines = document.lines # Scan upwards, until we find a point where we can ...
Scan backwards, and find a possible position to start.
get_sync_start_position
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def from_pygments_lexer_cls(cls, lexer_cls: PygmentsLexerCls) -> RegexSync: """ Create a :class:`.RegexSync` instance for this Pygments lexer class. """ patterns = { # For Python, start highlighting at any class/def block. "Python": r"^\s*(class|def)\s+", ...
Create a :class:`.RegexSync` instance for this Pygments lexer class.
from_pygments_lexer_cls
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def lex_document(self, document: Document) -> Callable[[int], StyleAndTextTuples]: """ Create a lexer function that takes a line number and returns the list of (style_str, text) tuples as the Pygments lexer returns for that line. """ LineGenerator = Generator[Tuple[int, StyleAndT...
Create a lexer function that takes a line number and returns the list of (style_str, text) tuples as the Pygments lexer returns for that line.
lex_document
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def get_syntax_sync() -> SyntaxSync: "The Syntax synchronization object that we currently use." if self.sync_from_start(): return SyncFromStart() else: return self.syntax_sync
The Syntax synchronization object that we currently use.
get_syntax_sync
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def find_closest_generator(i: int) -> LineGenerator | None: "Return a generator close to line 'i', or None if none was found." for generator, lineno in line_generators.items(): if lineno < i and i - lineno < self.REUSE_GENERATOR_MAX_DISTANCE: return generator ...
Return a generator close to line 'i', or None if none was found.
find_closest_generator
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def create_line_generator(start_lineno: int, column: int = 0) -> LineGenerator: """ Create a generator that yields the lexed lines. Each iteration it yields a (line_number, [(style_str, text), ...]) tuple. """ def get_text_fragments() -> Iterable[tuple[str, s...
Create a generator that yields the lexed lines. Each iteration it yields a (line_number, [(style_str, text), ...]) tuple.
create_line_generator
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def get_generator(i: int) -> LineGenerator: """ Find an already started generator that is close, or create a new one. """ # Find closest line generator. generator = find_closest_generator(i) if generator: return generator ...
Find an already started generator that is close, or create a new one.
get_generator
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def get_line(i: int) -> StyleAndTextTuples: "Return the tokens for a given line number." try: return cache[i] except KeyError: generator = get_generator(i) # Exhaust the generator, until we find the requested line. for ...
Return the tokens for a given line number.
get_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/lexers/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/lexers/pygments.py
BSD-3-Clause
def encoding(self) -> str: """ Return the encoding for this output, e.g. 'utf-8'. (This is used mainly to know which characters are supported by the output the data, so that the UI can provide alternatives, when required.) """
Return the encoding for this output, e.g. 'utf-8'. (This is used mainly to know which characters are supported by the output the data, so that the UI can provide alternatives, when required.)
encoding
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def erase_screen(self) -> None: """ Erases the screen with the background color and moves the cursor to home. """
Erases the screen with the background color and moves the cursor to home.
erase_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def erase_end_of_line(self) -> None: """ Erases from the current cursor position to the end of the current line. """
Erases from the current cursor position to the end of the current line.
erase_end_of_line
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def erase_down(self) -> None: """ Erases the screen from the current line down to the bottom of the screen. """
Erases the screen from the current line down to the bottom of the screen.
erase_down
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def ask_for_cpr(self) -> None: """ Asks for a cursor position report (CPR). (VT100 only.) """
Asks for a cursor position report (CPR). (VT100 only.)
ask_for_cpr
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def reset_cursor_key_mode(self) -> None: """ For vt100 only. Put the terminal in normal cursor mode (instead of application mode). See: https://vt100.net/docs/vt100-ug/chapter3.html """
For vt100 only. Put the terminal in normal cursor mode (instead of application mode). See: https://vt100.net/docs/vt100-ug/chapter3.html
reset_cursor_key_mode
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def get_default_color_depth(self) -> ColorDepth: """ Get default color depth for this output. This value will be used if no color depth was explicitly passed to the `Application`. .. note:: If the `$PROMPT_TOOLKIT_COLOR_DEPTH` environment variable has been ...
Get default color depth for this output. This value will be used if no color depth was explicitly passed to the `Application`. .. note:: If the `$PROMPT_TOOLKIT_COLOR_DEPTH` environment variable has been set, then `outputs.defaults.create_output` will pass thi...
get_default_color_depth
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/base.py
BSD-3-Clause
def from_env(cls) -> ColorDepth | None: """ Return the color depth if the $PROMPT_TOOLKIT_COLOR_DEPTH environment variable has been set. This is a way to enforce a certain color depth in all prompt_toolkit applications. """ # Disable color if a `NO_COLOR` environ...
Return the color depth if the $PROMPT_TOOLKIT_COLOR_DEPTH environment variable has been set. This is a way to enforce a certain color depth in all prompt_toolkit applications.
from_env
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/color_depth.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/color_depth.py
BSD-3-Clause
def create_output( stdout: TextIO | StdoutProxy | None = None, always_prefer_tty: bool = False ) -> Output: """ Return an :class:`~prompt_toolkit.output.Output` instance for the command line. :param stdout: The stdout object :param always_prefer_tty: When set, look for `sys.stderr` if `sys.stdo...
Return an :class:`~prompt_toolkit.output.Output` instance for the command line. :param stdout: The stdout object :param always_prefer_tty: When set, look for `sys.stderr` if `sys.stdout` is not a TTY. Useful if `sys.stdout` is redirected to a file, but we still want user input and outp...
create_output
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/defaults.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/defaults.py
BSD-3-Clause
def _blocking_io(io: IO[str]) -> Iterator[None]: """ Ensure that the FD for `io` is set to blocking in here. """ if sys.platform == "win32": # On Windows, the `os` module doesn't have a `get/set_blocking` # function. yield return try: fd = io.fileno() ...
Ensure that the FD for `io` is set to blocking in here.
_blocking_io
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/flush_stdout.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/flush_stdout.py
BSD-3-Clause
def _get_closest_ansi_color(r: int, g: int, b: int, exclude: Sequence[str] = ()) -> str: """ Find closest ANSI color. Return it by name. :param r: Red (Between 0 and 255.) :param g: Green (Between 0 and 255.) :param b: Blue (Between 0 and 255.) :param exclude: A tuple of color names to exclude....
Find closest ANSI color. Return it by name. :param r: Red (Between 0 and 255.) :param g: Green (Between 0 and 255.) :param b: Blue (Between 0 and 255.) :param exclude: A tuple of color names to exclude. (E.g. ``('ansired', )``.)
_get_closest_ansi_color
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def get_code( self, value: tuple[int, int, int], exclude: Sequence[str] = () ) -> _ColorCodeAndName: """ Return a (ansi_code, ansi_name) tuple. (E.g. ``(44, 'ansiblue')``.) for a given (r,g,b) value. """ key: Hashable = (value, tuple(exclude)) cache = self._ca...
Return a (ansi_code, ansi_name) tuple. (E.g. ``(44, 'ansiblue')``.) for a given (r,g,b) value.
get_code
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def _colors_to_code(self, fg_color: str, bg_color: str) -> Iterable[str]: """ Return a tuple with the vt100 values that represent this color. """ # When requesting ANSI colors only, and both fg/bg color were converted # to ANSI, ensure that the foreground and background color ar...
Return a tuple with the vt100 values that represent this color.
_colors_to_code
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def _get_size(fileno: int) -> tuple[int, int]: """ Get the size of this pseudo terminal. :param fileno: stdout.fileno() :returns: A (rows, cols) tuple. """ size = os.get_terminal_size(fileno) return size.lines, size.columns
Get the size of this pseudo terminal. :param fileno: stdout.fileno() :returns: A (rows, cols) tuple.
_get_size
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def from_pty( cls, stdout: TextIO, term: str | None = None, default_color_depth: ColorDepth | None = None, enable_bell: bool = True, ) -> Vt100_Output: """ Create an Output class from a pseudo terminal. (This will take the dimensions by reading the pse...
Create an Output class from a pseudo terminal. (This will take the dimensions by reading the pseudo terminal attributes.)
from_pty
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def set_attributes(self, attrs: Attrs, color_depth: ColorDepth) -> None: """ Create new style and output. :param attrs: `Attrs` instance. """ # Get current depth. escape_code_cache = self._escape_code_caches[color_depth] # Write escape character. self.wr...
Create new style and output. :param attrs: `Attrs` instance.
set_attributes
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def flush(self) -> None: """ Write to output stream and flush. """ if not self._buffer: return data = "".join(self._buffer) self._buffer = [] flush_stdout(self.stdout, data)
Write to output stream and flush.
flush
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def get_default_color_depth(self) -> ColorDepth: """ Return the default color depth for a vt100 terminal, according to the our term value. We prefer 256 colors almost always, because this is what most terminals support these days, and is a good default. """ if se...
Return the default color depth for a vt100 terminal, according to the our term value. We prefer 256 colors almost always, because this is what most terminals support these days, and is a good default.
get_default_color_depth
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/vt100.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/vt100.py
BSD-3-Clause
def _winapi(self, func: Callable[..., _T], *a: object, **kw: object) -> _T: """ Flush and call win API function. """ self.flush() if _DEBUG_RENDER_OUTPUT: self.LOG.write((f"{func.__name__!r}").encode() + b"\n") self.LOG.write( b" " + "...
Flush and call win API function.
_winapi
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def reset_attributes(self) -> None: "Reset the console foreground/background color." self._winapi( windll.kernel32.SetConsoleTextAttribute, self.hconsole, self.default_attrs ) self._hidden = False
Reset the console foreground/background color.
reset_attributes
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def scroll_buffer_to_prompt(self) -> None: """ To be called before drawing the prompt. This should scroll the console to left, with the cursor at the bottom (if possible). """ # Get current window size info = self.get_win32_screen_buffer_info() sr = info.srWindow ...
To be called before drawing the prompt. This should scroll the console to left, with the cursor at the bottom (if possible).
scroll_buffer_to_prompt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def quit_alternate_screen(self) -> None: """ Make stdout again the active buffer. """ if self._in_alternate_screen: stdout = HANDLE( self._winapi(windll.kernel32.GetStdHandle, STD_OUTPUT_HANDLE) ) self._winapi(windll.kernel32.SetConsole...
Make stdout again the active buffer.
quit_alternate_screen
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def win32_refresh_window(cls) -> None: """ Call win32 API to refresh the whole Window. This is sometimes necessary when the application paints background for completion menus. When the menu disappears, it leaves traces due to a bug in the Windows Console. Sending a repaint reque...
Call win32 API to refresh the whole Window. This is sometimes necessary when the application paints background for completion menus. When the menu disappears, it leaves traces due to a bug in the Windows Console. Sending a repaint request solves it.
win32_refresh_window
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def get_default_color_depth(self) -> ColorDepth: """ Return the default color depth for a windows terminal. Contrary to the Vt100 implementation, this doesn't depend on a $TERM variable. """ if self.default_color_depth is not None: return self.default_color_d...
Return the default color depth for a windows terminal. Contrary to the Vt100 implementation, this doesn't depend on a $TERM variable.
get_default_color_depth
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def _create_ansi_color_dict( color_cls: type[FOREGROUND_COLOR] | type[BACKGROUND_COLOR], ) -> dict[str, int]: "Create a table that maps the 16 named ansi colors to their Windows code." return { "ansidefault": color_cls.BLACK, "ansiblack": color_cls.BLACK, "ansigray": color_cls.GRAY, ...
Create a table that maps the 16 named ansi colors to their Windows code.
_create_ansi_color_dict
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def _build_color_table() -> list[tuple[int, int, int, int, int]]: """ Build an RGB-to-256 color conversion table """ FG = FOREGROUND_COLOR BG = BACKGROUND_COLOR return [ (0x00, 0x00, 0x00, FG.BLACK, BG.BLACK), (0x00, 0x00, 0xAA, FG.BLUE, BG.BLUE),...
Build an RGB-to-256 color conversion table
_build_color_table
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def lookup_fg_color(self, fg_color: str) -> int: """ Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param fg_color: Foreground as text. E.g. 'ffffff' or 'red' """ # Foreground. if fg_color in FG_ANSI_COLORS: retur...
Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param fg_color: Foreground as text. E.g. 'ffffff' or 'red'
lookup_fg_color
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def lookup_bg_color(self, bg_color: str) -> int: """ Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param bg_color: Background as text. E.g. 'ffffff' or 'red' """ # Background. if bg_color in BG_ANSI_COLORS: retur...
Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param bg_color: Background as text. E.g. 'ffffff' or 'red'
lookup_bg_color
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/output/win32.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/output/win32.py
BSD-3-Clause
def yes_no_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", yes_text: str = "Yes", no_text: str = "No", style: BaseStyle | None = None, ) -> Application[bool]: """ Display a Yes/No dialog. Return a boolean. """ def yes_handler() -> None: get_app().exit(...
Display a Yes/No dialog. Return a boolean.
yes_no_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def button_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", buttons: list[tuple[str, _T]] = [], style: BaseStyle | None = None, ) -> Application[_T]: """ Display a dialog with button choices (given as a list of tuples). Return the value associated with button. """ ...
Display a dialog with button choices (given as a list of tuples). Return the value associated with button.
button_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def input_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", ok_text: str = "OK", cancel_text: str = "Cancel", completer: Completer | None = None, validator: Validator | None = None, password: FilterOrBool = False, style: BaseStyle | None = None, default: str = "", ) ...
Display a text input box. Return the given text, or None when cancelled.
input_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def message_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", ok_text: str = "Ok", style: BaseStyle | None = None, ) -> Application[None]: """ Display a simple message box and wait until the user presses enter. """ dialog = Dialog( title=title, body=Label...
Display a simple message box and wait until the user presses enter.
message_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def radiolist_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", ok_text: str = "Ok", cancel_text: str = "Cancel", values: Sequence[tuple[_T, AnyFormattedText]] | None = None, default: _T | None = None, style: BaseStyle | None = None, ) -> Application[_T]: """ Display...
Display a simple list of element the user can choose amongst. Only one element can be selected at a time using Arrow keys and Enter. The focus can be moved between the list and the Ok/Cancel button with tab.
radiolist_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def checkboxlist_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", ok_text: str = "Ok", cancel_text: str = "Cancel", values: Sequence[tuple[_T, AnyFormattedText]] | None = None, default_values: Sequence[_T] | None = None, style: BaseStyle | None = None, ) -> Application[list...
Display a simple list of element the user can choose multiple values amongst. Several elements can be selected at a time using Arrow keys and Enter. The focus can be moved between the list and the Ok/Cancel button with tab.
checkboxlist_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def progress_dialog( title: AnyFormattedText = "", text: AnyFormattedText = "", run_callback: Callable[[Callable[[int], None], Callable[[str], None]], None] = ( lambda *a: None ), style: BaseStyle | None = None, ) -> Application[None]: """ :param run_callback: A function that receive...
:param run_callback: A function that receives as input a `set_percentage` function and it does the work.
progress_dialog
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/dialogs.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/dialogs.py
BSD-3-Clause
def _split_multiline_prompt( get_prompt_text: _StyleAndTextTuplesCallable, ) -> tuple[ Callable[[], bool], _StyleAndTextTuplesCallable, _StyleAndTextTuplesCallable ]: """ Take a `get_prompt_text` function and return three new functions instead. One that tells whether this prompt consists of multiple...
Take a `get_prompt_text` function and return three new functions instead. One that tells whether this prompt consists of multiple lines; one that returns the fragments to be shown on the lines above the input; and another one with the fragments to be shown at the first line of the input.
_split_multiline_prompt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _dyncond(self, attr_name: str) -> Condition: """ Dynamically take this setting from this 'PromptSession' class. `attr_name` represents an attribute name of this class. Its value can either be a boolean or a `Filter`. This returns something that can be used as either a `Filte...
Dynamically take this setting from this 'PromptSession' class. `attr_name` represents an attribute name of this class. Its value can either be a boolean or a `Filter`. This returns something that can be used as either a `Filter` or `Filter`.
_dyncond
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _create_default_buffer(self) -> Buffer: """ Create and return the default input buffer. """ dyncond = self._dyncond # Create buffers list. def accept(buff: Buffer) -> bool: """Accept the content of the default buffer. This is called when the v...
Create and return the default input buffer.
_create_default_buffer
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def accept(buff: Buffer) -> bool: """Accept the content of the default buffer. This is called when the validation succeeds.""" cast(Application[str], get_app()).exit(result=buff.document.text) return True # Keep text, we call 'reset' later on.
Accept the content of the default buffer. This is called when the validation succeeds.
accept
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def get_search_buffer_control() -> SearchBufferControl: "Return the UIControl to be focused when searching start." if is_true(self.multiline): return search_toolbar.control else: return search_buffer_control
Return the UIControl to be focused when searching start.
get_search_buffer_control
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _create_prompt_bindings(self) -> KeyBindings: """ Create the KeyBindings for a prompt application. """ kb = KeyBindings() handle = kb.add default_focused = has_focus(DEFAULT_BUFFER) @Condition def do_accept() -> bool: return not is_true(se...
Create the KeyBindings for a prompt application.
_create_prompt_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def ctrl_d_condition() -> bool: """Ctrl-D binding is only active when the default buffer is selected and empty.""" app = get_app() return ( app.current_buffer.name == DEFAULT_BUFFER and not app.current_buffer.text )
Ctrl-D binding is only active when the default buffer is selected and empty.
ctrl_d_condition
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def prompt( self, # When any of these arguments are passed, this value is overwritten # in this PromptSession. message: AnyFormattedText | None = None, # `message` should go first, because people call it as # positional argument. *, editing_mode: EditingMo...
Display the prompt. The first set of arguments is a subset of the :class:`~.PromptSession` class itself. For these, passing in ``None`` will keep the current values that are active in the session. Passing in a value will set the attribute for the session, which means that it ap...
prompt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _dumb_prompt(self, message: AnyFormattedText = "") -> Iterator[Application[_T]]: """ Create prompt `Application` for prompt function for dumb terminals. Dumb terminals have minimum rendering capabilities. We can only print text to the screen. We can't use colors, and we can't do cur...
Create prompt `Application` for prompt function for dumb terminals. Dumb terminals have minimum rendering capabilities. We can only print text to the screen. We can't use colors, and we can't do cursor movements. The Emacs inferior shell is an example of a dumb terminal. We wi...
_dumb_prompt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _get_continuation( self, width: int, line_number: int, wrap_count: int ) -> StyleAndTextTuples: """ Insert the prompt continuation. :param width: The width that was used for the prompt. (more or less can be used.) :param line_number: :param wrap_count...
Insert the prompt continuation. :param width: The width that was used for the prompt. (more or less can be used.) :param line_number: :param wrap_count: Amount of times that the line has been wrapped.
_get_continuation
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _get_line_prefix( self, line_number: int, wrap_count: int, get_prompt_text_2: _StyleAndTextTuplesCallable, ) -> StyleAndTextTuples: """ Return whatever needs to be inserted before every line. (the prompt, or a line continuation.) """ # Firs...
Return whatever needs to be inserted before every line. (the prompt, or a line continuation.)
_get_line_prefix
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _get_arg_text(self) -> StyleAndTextTuples: "'arg' toolbar, for in multiline mode." arg = self.app.key_processor.arg if arg is None: # Should not happen because of the `has_arg` filter in the layout. return [] if arg == "-": arg = "-1" ret...
'arg' toolbar, for in multiline mode.
_get_arg_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def _inline_arg(self) -> StyleAndTextTuples: "'arg' prefix, for in single line mode." app = get_app() if app.key_processor.arg is None: return [] else: arg = app.key_processor.arg return [ ("class:prompt.arg", "(arg: "), ...
'arg' prefix, for in single line mode.
_inline_arg
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def prompt( message: AnyFormattedText | None = None, *, history: History | None = None, editing_mode: EditingMode | None = None, refresh_interval: float | None = None, vi_mode: bool | None = None, lexer: Lexer | None = None, completer: Completer | None = None, complete_in_thread: boo...
The global `prompt` function. This will create a new `PromptSession` instance for every call.
prompt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def create_confirm_session( message: str, suffix: str = " (y/n) " ) -> PromptSession[bool]: """ Create a `PromptSession` object for the 'confirm' function. """ bindings = KeyBindings() @bindings.add("y") @bindings.add("Y") def yes(event: E) -> None: session.default_buffer.text =...
Create a `PromptSession` object for the 'confirm' function.
create_confirm_session
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/prompt.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/prompt.py
BSD-3-Clause
def print_formatted_text( *values: Any, sep: str = " ", end: str = "\n", file: TextIO | None = None, flush: bool = False, style: BaseStyle | None = None, output: Output | None = None, color_depth: ColorDepth | None = None, style_transformation: StyleTransformation | None = None, ...
:: print_formatted_text(*values, sep=' ', end='\n', file=None, flush=False, style=None, output=None) Print text to stdout. This is supposed to be compatible with Python's print function, but supports printing of formatted text. You can pass a :class:`~prompt_toolkit.formatted_text.FormattedTe...
print_formatted_text
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/utils.py
BSD-3-Clause
def print_container( container: AnyContainer, file: TextIO | None = None, style: BaseStyle | None = None, include_default_pygments_style: bool = True, ) -> None: """ Print any layout to the output in a non-interactive way. Example usage:: from prompt_toolkit.widgets import Frame, T...
Print any layout to the output in a non-interactive way. Example usage:: from prompt_toolkit.widgets import Frame, TextArea print_container( Frame(TextArea(text='Hello world!')))
print_container
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/utils.py
BSD-3-Clause
def _create_merged_style( style: BaseStyle | None, include_default_pygments_style: bool ) -> BaseStyle: """ Merge user defined style with built-in style. """ styles = [default_ui_style()] if include_default_pygments_style: styles.append(default_pygments_style()) if style: sty...
Merge user defined style with built-in style.
_create_merged_style
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/utils.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/utils.py
BSD-3-Clause
def create_key_bindings(cancel_callback: Callable[[], None] | None) -> KeyBindings: """ Key bindings handled by the progress bar. (The main thread is not supposed to handle any key bindings.) """ kb = KeyBindings() @kb.add("c-l") def _clear(event: E) -> None: event.app.renderer.clea...
Key bindings handled by the progress bar. (The main thread is not supposed to handle any key bindings.)
create_key_bindings
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/base.py
BSD-3-Clause
def _interrupt(event: E) -> None: "Kill the 'body' of the progress bar, but only if we run from the main thread." assert cancel_callback is not None cancel_callback()
Kill the 'body' of the progress bar, but only if we run from the main thread.
_interrupt
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/base.py
BSD-3-Clause
def __call__( self, data: Iterable[_T] | None = None, label: AnyFormattedText = "", remove_when_done: bool = False, total: int | None = None, ) -> ProgressBarCounter[_T]: """ Start a new counter. :param label: Title text or description for this progre...
Start a new counter. :param label: Title text or description for this progress. (This can be formatted text as well). :param remove_when_done: When `True`, hide this progress bar. :param total: Specify the maximum value if it can't be calculated by calling ``len...
__call__
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/base.py
BSD-3-Clause
def time_elapsed(self) -> datetime.timedelta: """ Return how much time has been elapsed since the start. """ if self.stop_time is None: return datetime.datetime.now() - self.start_time else: return self.stop_time - self.start_time
Return how much time has been elapsed since the start.
time_elapsed
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/base.py
BSD-3-Clause
def _format_timedelta(timedelta: datetime.timedelta) -> str: """ Return hh:mm:ss, or mm:ss if the amount of hours is zero. """ result = f"{timedelta}".split(".")[0] if result.startswith("0:"): result = result[2:] return result
Return hh:mm:ss, or mm:ss if the amount of hours is zero.
_format_timedelta
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/formatters.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/formatters.py
BSD-3-Clause
def create_default_formatters() -> list[Formatter]: """ Return the list of default formatters. """ return [ Label(), Text(" "), Percentage(), Text(" "), Bar(), Text(" "), Progress(), Text(" "), Text("eta [", style="class:time-left")...
Return the list of default formatters.
create_default_formatters
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/shortcuts/progress_bar/formatters.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/shortcuts/progress_bar/formatters.py
BSD-3-Clause
def get_attrs_for_style_str( self, style_str: str, default: Attrs = DEFAULT_ATTRS ) -> Attrs: """ Return :class:`.Attrs` for the given style string. :param style_str: The style string. This can contain inline styling as well as classnames (e.g. "class:title"). :p...
Return :class:`.Attrs` for the given style string. :param style_str: The style string. This can contain inline styling as well as classnames (e.g. "class:title"). :param default: `Attrs` to be used if no styling was defined.
get_attrs_for_style_str
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/base.py
BSD-3-Clause
def invalidation_hash(self) -> Hashable: """ Invalidation hash for the style. When this changes over time, the renderer knows that something in the style changed, and that everything has to be redrawn. """
Invalidation hash for the style. When this changes over time, the renderer knows that something in the style changed, and that everything has to be redrawn.
invalidation_hash
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/base.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/base.py
BSD-3-Clause
def style_from_pygments_cls(pygments_style_cls: type[PygmentsStyle]) -> Style: """ Shortcut to create a :class:`.Style` instance from a Pygments style class and a style dictionary. Example:: from prompt_toolkit.styles.from_pygments import style_from_pygments_cls from pygments.styles im...
Shortcut to create a :class:`.Style` instance from a Pygments style class and a style dictionary. Example:: from prompt_toolkit.styles.from_pygments import style_from_pygments_cls from pygments.styles import get_style_by_name style = style_from_pygments_cls(get_style_by_name('mono...
style_from_pygments_cls
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/pygments.py
BSD-3-Clause
def style_from_pygments_dict(pygments_dict: dict[Token, str]) -> Style: """ Create a :class:`.Style` instance from a Pygments style dictionary. (One that maps Token objects to style strings.) """ pygments_style = [] for token, style in pygments_dict.items(): pygments_style.append((pygme...
Create a :class:`.Style` instance from a Pygments style dictionary. (One that maps Token objects to style strings.)
style_from_pygments_dict
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/pygments.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/pygments.py
BSD-3-Clause
def parse_color(text: str) -> str: """ Parse/validate color format. Like in Pygments, but also support the ANSI color names. (These will map to the colors of the 16 color palette.) """ # ANSI color names. if text in ANSI_COLOR_NAMES: return text if text in ANSI_COLOR_NAMES_ALIAS...
Parse/validate color format. Like in Pygments, but also support the ANSI color names. (These will map to the colors of the 16 color palette.)
parse_color
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def _expand_classname(classname: str) -> list[str]: """ Split a single class name at the `.` operator, and build a list of classes. E.g. 'a.b.c' becomes ['a', 'a.b', 'a.b.c'] """ result = [] parts = classname.split(".") for i in range(1, len(parts) + 1): result.append(".".join(part...
Split a single class name at the `.` operator, and build a list of classes. E.g. 'a.b.c' becomes ['a', 'a.b', 'a.b.c']
_expand_classname
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def _parse_style_str(style_str: str) -> Attrs: """ Take a style string, e.g. 'bg:red #88ff00 class:title' and return a `Attrs` instance. """ # Start from default Attrs. if "noinherit" in style_str: attrs = DEFAULT_ATTRS else: attrs = _EMPTY_ATTRS # Now update with the g...
Take a style string, e.g. 'bg:red #88ff00 class:title' and return a `Attrs` instance.
_parse_style_str
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def from_dict( cls, style_dict: dict[str, str], priority: Priority = default_priority ) -> Style: """ :param style_dict: Style dictionary. :param priority: `Priority` value. """ if priority == Priority.MOST_PRECISE: def key(item: tuple[str, str]) -> int: ...
:param style_dict: Style dictionary. :param priority: `Priority` value.
from_dict
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def get_attrs_for_style_str( self, style_str: str, default: Attrs = DEFAULT_ATTRS ) -> Attrs: """ Get `Attrs` for the given style string. """ list_of_attrs = [default] class_names: set[str] = set() # Apply default styling. for names, attr in self.clas...
Get `Attrs` for the given style string.
get_attrs_for_style_str
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def _merge_attrs(list_of_attrs: list[Attrs]) -> Attrs: """ Take a list of :class:`.Attrs` instances and merge them into one. Every `Attr` in the list can override the styling of the previous one. So, the last one has highest priority. """ def _or(*values: _T) -> _T: "Take first not-None...
Take a list of :class:`.Attrs` instances and merge them into one. Every `Attr` in the list can override the styling of the previous one. So, the last one has highest priority.
_merge_attrs
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def _or(*values: _T) -> _T: "Take first not-None value, starting at the end." for v in values[::-1]: if v is not None: return v raise ValueError # Should not happen, there's always one non-null value.
Take first not-None value, starting at the end.
_or
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def _merged_style(self) -> Style: "The `Style` object that has the other styles merged together." def get() -> Style: return Style(self.style_rules) return self._style.get(self.invalidation_hash(), get)
The `Style` object that has the other styles merged together.
_merged_style
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style.py
BSD-3-Clause
def transform_attrs(self, attrs: Attrs) -> Attrs: """ Take an `Attrs` object and return a new `Attrs` object. Remember that the color formats can be either "ansi..." or a 6 digit lowercase hexadecimal color (without '#' prefix). """
Take an `Attrs` object and return a new `Attrs` object. Remember that the color formats can be either "ansi..." or a 6 digit lowercase hexadecimal color (without '#' prefix).
transform_attrs
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style_transformation.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style_transformation.py
BSD-3-Clause
def transform_attrs(self, attrs: Attrs) -> Attrs: """ Return the `Attrs` used when opposite luminosity should be used. """ # Reverse colors. attrs = attrs._replace(color=get_opposite_color(attrs.color)) attrs = attrs._replace(bgcolor=get_opposite_color(attrs.bgcolor)) ...
Return the `Attrs` used when opposite luminosity should be used.
transform_attrs
python
prompt-toolkit/python-prompt-toolkit
src/prompt_toolkit/styles/style_transformation.py
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/styles/style_transformation.py
BSD-3-Clause