repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
textual | src/textual/widgets/collapsible.py | .py | from textual.widgets._collapsible import CollapsibleTitle
__all__ = ["CollapsibleTitle"]
| 4 | 90 |
textual | src/textual/widgets/_tab_pane.py | .py | from textual.widgets._tabbed_content import TabPane
__all__ = ["TabPane"]
| 4 | 75 |
textual | src/textual/widgets/_toast.py | .py | """Widgets for showing notification messages in toasts."""
from __future__ import annotations
from typing import ClassVar
from textual import on
from textual.containers import Container
from textual.content import Content
from textual.css.query import NoMatches
from textual.events import Click, Mount
from textual.no... | 207 | 5,976 |
textual | src/textual/widgets/_radio_set.py | .py | """Provides a RadioSet widget, which groups radio buttons."""
from __future__ import annotations
from typing import ClassVar, Optional
import rich.repr
from rich.console import RenderableType
from textual import _widget_navigation
from textual.binding import Binding, BindingType
from textual.containers import Verti... | 316 | 11,492 |
textual | src/textual/widgets/_switch.py | .py | from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar
from rich.console import RenderableType
if TYPE_CHECKING:
from textual.app import RenderResult
from typing_extensions import Self
from textual.binding import Binding, BindingType
from textual.events import Click
from textual.geome... | 222 | 6,305 |
textual | src/textual/document/_syntax_aware_document.py | .py | from __future__ import annotations
try:
from tree_sitter import Language, Node, Parser, Query, QueryCursor, Tree
TREE_SITTER = True
except ImportError:
TREE_SITTER = False
from textual.document._document import Document, EditResult, Location, _utf8_encode
_UINT32_MAX = 0xFFFFFFFF
class SyntaxAwareDoc... | 235 | 7,915 |
textual | src/textual/document/_wrapped_document.py | .py | from __future__ import annotations
from bisect import bisect_right
from rich.text import Text
from textual._cells import cell_len, cell_width_to_column_index
from textual._wrap import compute_wrap_offsets
from textual.document._document import DocumentBase, Location
from textual.expand_tabs import expand_tabs_inline... | 455 | 17,779 |
textual | src/textual/document/_document.py | .py | from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import dataclass
from functools import lru_cache
from typing import TYPE_CHECKING, NamedTuple, Tuple, overload
from typing_extensions import Literal, get_args
if TYPE_CHECKING:
from tree_sitter import Node, Query
from textua... | 474 | 15,067 |
textual | src/textual/document/_history.py | .py | from __future__ import annotations
import time
from collections import deque
from dataclasses import dataclass, field
from textual.document._edit import Edit
class HistoryException(Exception):
"""Indicates misuse of the EditHistory API.
For example, trying to undo() an Edit that has yet to be done.
"""... | 184 | 7,061 |
textual | src/textual/document/_document_navigator.py | .py | import re
from bisect import bisect, bisect_left, bisect_right
from typing import Any, Sequence
from textual._cells import cell_len
from textual.document._document import Location
from textual.document._wrapped_document import WrappedDocument
from textual.geometry import Offset, clamp
class DocumentNavigator:
""... | 471 | 18,340 |
textual | src/textual/document/_edit.py | .py | from __future__ import annotations
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
from textual.document._document import EditResult, Location, Selection
if TYPE_CHECKING:
from textual.widgets import TextArea
@dataclass
class Edit:
"""Implements the Undoable protocol to replace te... | 152 | 5,707 |
textual | src/textual/layouts/horizontal.py | .py | from __future__ import annotations
from fractions import Fraction
from typing import TYPE_CHECKING
from textual._resolve import resolve_box_models
from textual.geometry import NULL_OFFSET, Region, Size
from textual.layout import ArrangeResult, Layout, WidgetPlacement
if TYPE_CHECKING:
from textual.geometry impor... | 121 | 3,867 |
textual | src/textual/layouts/vertical.py | .py | from __future__ import annotations
from fractions import Fraction
from typing import TYPE_CHECKING
from textual._resolve import resolve_box_models
from textual.geometry import NULL_OFFSET, Region, Size
from textual.layout import ArrangeResult, Layout, WidgetPlacement
if TYPE_CHECKING:
from textual.geometry impor... | 125 | 3,913 |
textual | src/textual/layouts/grid.py | .py | from __future__ import annotations
from fractions import Fraction
from typing import TYPE_CHECKING, Iterable
from textual._resolve import resolve
from textual.css.scalar import Scalar
from textual.geometry import NULL_OFFSET, Region, Size, Spacing
from textual.layout import ArrangeResult, Layout, WidgetPlacement
from... | 377 | 13,661 |
textual | src/textual/layouts/factory.py | .py | from __future__ import annotations
from textual.layout import Layout
from textual.layouts.grid import GridLayout
from textual.layouts.horizontal import HorizontalLayout
from textual.layouts.stream import StreamLayout
from textual.layouts.vertical import VerticalLayout
LAYOUT_MAP: dict[str, type[Layout]] = {
"hori... | 38 | 881 |
textual | src/textual/layouts/stream.py | .py | from __future__ import annotations
from itertools import zip_longest
from typing import TYPE_CHECKING
from textual.geometry import NULL_OFFSET, Region, Size
from textual.layout import ArrangeResult, Layout, WidgetPlacement
if TYPE_CHECKING:
from textual.widget import Widget
class StreamLayout(Layout):
"""A... | 150 | 5,169 |
textual | src/textual/drivers/_writer_thread.py | .py | from __future__ import annotations
import threading
from queue import Queue
from typing import IO
from typing_extensions import Final
MAX_QUEUED_WRITES: Final[int] = 30
class WriterThread(threading.Thread):
"""A thread / file-like to do writes to stdout in the background."""
def __init__(self, file: IO[st... | 69 | 1,733 |
textual | src/textual/drivers/windows_driver.py | .py | from __future__ import annotations
import asyncio
import sys
from threading import Event, Thread
from typing import TYPE_CHECKING, Callable
from textual.driver import Driver
from textual.drivers import win32
from textual.drivers._writer_thread import WriterThread
if TYPE_CHECKING:
from textual.app import App
c... | 142 | 4,486 |
textual | src/textual/drivers/_byte_stream.py | .py | from __future__ import annotations
import io
from collections import deque
from typing import (
Callable,
Deque,
Generator,
Generic,
Iterable,
NamedTuple,
Tuple,
TypeVar,
)
from typing_extensions import TypeAlias
class ParseError(Exception):
"""Parse related errors."""
class Pa... | 158 | 4,052 |
textual | src/textual/drivers/_input_reader_windows.py | .py | import os
import sys
from threading import Event
from typing import Iterator
class InputReader:
"""Read input from stdin."""
def __init__(self, timeout: float = 0.1) -> None:
"""
Args:
timeout: Seconds to block for input.
"""
self._fileno = sys.__stdin__.fileno()
... | 34 | 830 |
textual | src/textual/drivers/linux_inline_driver.py | .py | from __future__ import annotations
import asyncio
import os
import selectors
import signal
import sys
import termios
import tty
from codecs import getincrementaldecoder
from threading import Event, Thread
from typing import TYPE_CHECKING, Any
import rich.repr
from textual import events
from textual._loop import loop... | 326 | 10,600 |
textual | src/textual/drivers/web_driver.py | .py | """
The Remote driver uses the following packet structure.
1 byte for packet type. "D" for data, "M" for meta.
4 byte little endian integer for the size of the payload.
Arbitrary payload.
"""
from __future__ import annotations
import asyncio
import json
import os
import signal
import sys
from codecs import getinc... | 355 | 12,324 |
textual | src/textual/drivers/linux_driver.py | .py | from __future__ import annotations
import asyncio
import os
import selectors
import signal
import sys
import termios
import tty
from codecs import getincrementaldecoder
from threading import Event, Thread
from typing import TYPE_CHECKING, Any, Final
import rich.repr
from textual import constants, events
from textual... | 486 | 16,950 |
textual | src/textual/drivers/_input_reader_linux.py | .py | import os
import selectors
import sys
from threading import Event
from typing import Iterator
class InputReader:
"""Read input from stdin."""
def __init__(self, timeout: float = 0.1) -> None:
"""
Args:
timeout: Seconds to block for input.
"""
self._fileno = sys.__... | 41 | 1,165 |
textual | src/textual/drivers/headless_driver.py | .py | from __future__ import annotations
import asyncio
from textual import events
from textual.driver import Driver
from textual.geometry import Size
class HeadlessDriver(Driver):
"""A do-nothing driver for testing."""
@property
def is_headless(self) -> bool:
"""Is the driver running in 'headless' m... | 67 | 1,888 |
textual | src/textual/drivers/win32.py | .py | from __future__ import annotations
import ctypes
import msvcrt
import sys
import threading
from asyncio import AbstractEventLoop, run_coroutine_threadsafe
from ctypes import Structure, Union, byref, wintypes
from ctypes.wintypes import BOOL, CHAR, DWORD, HANDLE, SHORT, UINT, WCHAR, WORD
from typing import IO, TYPE_CHE... | 305 | 9,697 |
textual | src/textual/drivers/_input_reader.py | .py | import sys
__all__ = ["InputReader"]
WINDOWS = sys.platform == "win32"
if WINDOWS:
from textual.drivers._input_reader_windows import InputReader
else:
from textual.drivers._input_reader_linux import InputReader
| 11 | 222 |
textual | src/textual/renderables/background_screen.py | .py | from __future__ import annotations
from typing import TYPE_CHECKING, Iterable
from rich.console import Console, ConsoleOptions, RenderResult
from rich.segment import Segment
from rich.style import Style
from textual.color import Color
if TYPE_CHECKING:
from textual.screen import Screen
class BackgroundScreen:... | 99 | 2,975 |
textual | src/textual/renderables/_blend_colors.py | .py | from __future__ import annotations
from rich.color import Color
def blend_colors(color1: Color, color2: Color, ratio: float) -> Color:
"""Given two RGB colors, return a color that sits some distance between
them in RGB color space.
Args:
color1: The first color.
color2: The second color.... | 28 | 732 |
textual | src/textual/renderables/bar.py | .py | from __future__ import annotations
from rich.console import Console, ConsoleOptions, RenderResult
from rich.style import Style, StyleType
from rich.text import Text
from textual.color import Gradient
class Bar:
"""Thin horizontal bar with a portion highlighted.
Args:
highlight_range: The range to h... | 156 | 5,112 |
textual | src/textual/renderables/digits.py | .py | from __future__ import annotations
from rich.console import Console, ConsoleOptions, RenderResult
from rich.measure import Measurement
from rich.segment import Segment
from rich.style import Style, StyleType
DIGITS = " 0123456789+-^x:ABCDEF$£€()"
DIGITS3X3_BOLD = """\
┏━┓
┃ ┃
┗━┛
╺┓
┃
╺┻╸
╺━┓
┏━┛
┗━╸
╺━┓
━┫
╺━┛
... | 254 | 3,692 |
textual | src/textual/renderables/sparkline.py | .py | from __future__ import annotations
import statistics
from fractions import Fraction
from typing import Callable, Generic, Iterable, Sequence, TypeVar
from rich.color import Color
from rich.console import Console, ConsoleOptions, RenderResult
from rich.measure import Measurement
from rich.segment import Segment
from r... | 166 | 5,475 |
textual | src/textual/renderables/tint.py | .py | from __future__ import annotations
from typing import Iterable
from rich.console import RenderableType
from rich.segment import Segment
from rich.style import Style
from rich.terminal_theme import TerminalTheme
from textual.color import TRANSPARENT, Color
from textual.filter import ANSIToTruecolor
class Tint:
... | 87 | 2,605 |
textual | src/textual/renderables/text_opacity.py | .py | import functools
from typing import Iterable, Tuple, cast
from rich.cells import cell_len
from rich.color import Color
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
from rich.segment import Segment
from rich.style import Style
from rich.terminal_theme import TerminalTheme
from textual... | 160 | 5,827 |
textual | src/textual/renderables/gradient.py | .py | from __future__ import annotations
from math import cos, pi, sin
from typing import Sequence
from rich.console import Console, ConsoleOptions, RenderResult
from rich.segment import Segment
from rich.style import Style
from textual.color import Color, Gradient
class VerticalGradient:
"""Draw a vertical gradient... | 171 | 4,631 |
textual | src/textual/renderables/styled.py | .py | from typing import TYPE_CHECKING
from rich.measure import Measurement
from rich.segment import Segment
if TYPE_CHECKING:
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
from rich.style import StyleType
class Styled:
"""A renderable which allows you to apply a style before ... | 51 | 1,937 |
textual | src/textual/renderables/blank.py | .py | from __future__ import annotations
from rich.style import Style as RichStyle
from textual.color import Color
from textual.content import Style
from textual.css.styles import RulesMap
from textual.strip import Strip
from textual.visual import RenderOptions, Visual
class Blank(Visual):
"""Draw solid background co... | 43 | 1,359 |
textual | src/textual/css/types.py | .py | from __future__ import annotations
from typing import Tuple
from typing_extensions import Literal
from textual.color import Color
DockEdge = Literal["none", "top", "right", "bottom", "left"]
EdgeType = Literal[
"",
"ascii",
"none",
"hidden",
"blank",
"round",
"solid",
"thick",
"b... | 93 | 2,164 |
textual | src/textual/css/scalar_animation.py | .py | from __future__ import annotations
from typing import TYPE_CHECKING
from textual._animator import Animation, EasingFunction
from textual._types import AnimationLevel, CallbackType
from textual.css.scalar import Scalar, ScalarOffset
if TYPE_CHECKING:
from textual.css.styles import StylesBase
from textual.widg... | 99 | 3,159 |
textual | src/textual/css/_styles_builder.py | .py | from __future__ import annotations
from typing import Iterable, NoReturn, cast
import rich.repr
from textual._border import BorderValue, normalize_border_value
from textual._cells import cell_len
from textual._duration import _duration_as_seconds
from textual._easing import EASING
from textual.color import TRANSPARE... | 1,317 | 49,495 |
textual | src/textual/css/parse.py | .py | from __future__ import annotations
import dataclasses
import re
from functools import lru_cache
from typing import Iterable, Iterator, NoReturn
from textual.css._help_renderables import HelpText
from textual.css._styles_builder import DeclarationError, StylesBuilder
from textual.css.errors import UnresolvedVariableEr... | 489 | 17,000 |
textual | src/textual/css/errors.py | .py | from __future__ import annotations
from rich.console import Console, ConsoleOptions, RenderResult
from textual.css._help_renderables import HelpText
from textual.css.tokenizer import Token, TokenError
class DeclarationError(Exception):
def __init__(self, name: str, token: Token, message: str | HelpText) -> None... | 51 | 1,304 |
textual | src/textual/css/_help_text.py | .py | from __future__ import annotations
from dataclasses import dataclass
from typing import Iterable, Sequence
from typing_extensions import Literal
from textual.color import ColorParseError
from textual.css._error_tools import friendly_list
from textual.css._help_renderables import Bullet, Example, HelpText
from textua... | 859 | 30,032 |
textual | src/textual/css/stylesheet.py | .py | from __future__ import annotations
import os
from collections import defaultdict
from itertools import chain
from operator import itemgetter
from pathlib import Path, PurePath
from typing import Final, Iterable, NamedTuple, Sequence, cast
import rich.repr
from rich.console import Console, ConsoleOptions, RenderableTy... | 738 | 27,148 |
textual | src/textual/css/model.py | .py | from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
from functools import partial
from typing import TYPE_CHECKING, Iterable
import rich.repr
from textual.css._help_renderables import HelpText
from textual.css.styles import Styles
from textual.css.tokenize import Token
f... | 307 | 8,750 |
textual | src/textual/css/constants.py | .py | from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from typing_extensions import Final
VALID_VISIBILITY: Final = {"visible", "hidden"}
VALID_DISPLAY: Final = {"block", "none"}
VALID_BORDER: Final = {
"ascii",
"blank",
"dashed",
"double",
"heavy",
"hidden",
"hkey... | 134 | 2,629 |
textual | src/textual/css/tokenize.py | .py | from __future__ import annotations
import re
from typing import TYPE_CHECKING, ClassVar, Iterable
from textual.css.tokenizer import Expect, Token, Tokenizer
if TYPE_CHECKING:
from textual.css.types import CSSLocation
PERCENT = r"-?\d+\.?\d*%"
DECIMAL = r"-?\d+\.?\d*"
COMMA = r"\s*,\s*"
OPEN_BRACE = r"\(\s*"
CLO... | 350 | 11,258 |
textual | src/textual/css/transition.py | .py | from typing import NamedTuple
class Transition(NamedTuple):
duration: float = 1.0
easing: str = "linear"
delay: float = 0.0
def __str__(self) -> str:
duration, easing, delay = self
if delay:
return f"{duration:.1f}s {easing} {delay:.1f}"
elif easing != "linear":
... | 17 | 417 |
textual | src/textual/css/styles.py | .py | from __future__ import annotations
import weakref
from dataclasses import dataclass, field
from functools import partial
from operator import attrgetter
from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Literal, cast
import rich.repr
from rich.style import Style
from typing_extensions import TypedD... | 1,529 | 52,117 |
textual | src/textual/css/match.py | .py | from __future__ import annotations
from typing import TYPE_CHECKING, Iterable
from textual.css.model import CombinatorType, Selector, SelectorSet
if TYPE_CHECKING:
from textual.dom import DOMNode
def match(selector_sets: Iterable[SelectorSet], node: DOMNode) -> bool:
"""Check if a given node matches any of... | 75 | 2,390 |
textual | src/textual/css/_style_properties.py | .py | """
Style properties are descriptors which allow the ``Styles`` object to accept different types when
setting attributes. This gives the developer more freedom in how to express style information.
Descriptors also play nicely with Mypy, which is aware that attributes can have different types
when setting and getting.
... | 1,259 | 43,257 |
textual | src/textual/css/tokenizer.py | .py | from __future__ import annotations
import re
from typing import TYPE_CHECKING, NamedTuple
import rich.repr
from rich.console import Group, RenderableType
from rich.highlighter import ReprHighlighter
from rich.padding import Padding
from rich.panel import Panel
from rich.text import Text
from textual.css._error_tools... | 385 | 11,826 |
textual | src/textual/css/query.py | .py | """
This module contains the `DOMQuery` class and related objects.
A DOMQuery is a set of DOM nodes returned by [query][textual.dom.DOMNode.query].
The set of nodes may be further refined with [filter][textual.css.query.DOMQuery.filter] and [exclude][textual.css.query.DOMQuery.exclude].
Additional methods apply actio... | 509 | 15,732 |
textual | src/textual/css/_error_tools.py | .py | from __future__ import annotations
from typing import Iterable
def friendly_list(
words: Iterable[str], joiner: str = "or", omit_empty: bool = True
) -> str:
"""Generate a list of words as readable prose.
>>> friendly_list(["foo", "bar", "baz"])
"'foo', 'bar', or 'baz'"
Args:
words: A l... | 31 | 743 |
textual | src/textual/css/scalar.py | .py | from __future__ import annotations
import re
from enum import Enum, unique
from fractions import Fraction
from functools import lru_cache
from typing import Iterable, NamedTuple
import rich.repr
from textual.geometry import Offset, Size, clamp
class ScalarError(Exception):
"""Base class for exceptions raised b... | 382 | 9,948 |
textual | src/textual/css/_help_renderables.py | .py | from __future__ import annotations
from typing import Iterable
import rich.repr
from rich.console import Console, ConsoleOptions, RenderResult
from rich.highlighter import ReprHighlighter
from rich.markup import render
from rich.text import Text
_highlighter = ReprHighlighter()
def _markup_and_highlight(text: str)... | 98 | 2,833 |
python-prompt-toolkit | tools/debug_vt100_input.py | .py | #!/usr/bin/env python
"""
Parse vt100 input and print keys.
For testing terminal input.
(This does not use the `Input` implementation, but only the `Vt100Parser`.)
"""
import sys
from prompt_toolkit.input.vt100 import raw_mode
from prompt_toolkit.input.vt100_parser import Vt100Parser
from prompt_toolkit.key_binding ... | 35 | 717 |
python-prompt-toolkit | tools/debug_input_cross_platform.py | .py | #!/usr/bin/env python
"""
Read input and print keys.
For testing terminal input.
Works on both Windows and Posix.
"""
import asyncio
from prompt_toolkit.input import create_input
from prompt_toolkit.keys import Keys
async def main() -> None:
done = asyncio.Event()
input = create_input()
def keys_ready... | 33 | 630 |
python-prompt-toolkit | tests/test_style.py | .py | from __future__ import annotations
from prompt_toolkit.styles import Attrs, Style, SwapLightAndDarkStyleTransformation
def test_style_from_dict():
style = Style.from_dict(
{
"a": "#ff0000 bold underline strike italic",
"b": "bg:#00ff00 blink reverse",
}
)
# Lookup... | 293 | 7,143 |
python-prompt-toolkit | tests/test_inputstream.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.input.vt100_parser import Vt100Parser
from prompt_toolkit.keys import Keys
class _ProcessorMock:
def __init__(self):
self.keys = []
def feed_key(self, key_press):
self.keys.append(key_press)
@pytest.fixture
def processor... | 142 | 4,060 |
python-prompt-toolkit | tests/test_history.py | .py | from __future__ import annotations
from asyncio import run
from prompt_toolkit.history import FileHistory, InMemoryHistory, ThreadedHistory
def _call_history_load(history):
"""
Helper: Call the history "load" method and return the result as a list of strings.
"""
result = []
async def call_load... | 104 | 3,069 |
python-prompt-toolkit | tests/test_document.py | .py | from __future__ import annotations
import re
import pytest
from prompt_toolkit.document import Document
@pytest.fixture
def document():
return Document(
"line 1\n" + "line 2\n" + "line 3\n" + "line 4\n", len("line 1\n" + "lin")
)
def test_current_char(document):
assert document.current_char =... | 82 | 2,014 |
python-prompt-toolkit | tests/test_filter.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.filters import Always, Condition, Filter, Never, to_filter
from prompt_toolkit.filters.base import _AndList, _OrList
def test_never():
assert not Never()()
def test_always():
assert Always()()
def test_invert():
assert not (~Always... | 132 | 3,532 |
python-prompt-toolkit | tests/test_shortcuts.py | .py | from __future__ import annotations
from prompt_toolkit.shortcuts import print_container
from prompt_toolkit.shortcuts.prompt import _split_multiline_prompt
from prompt_toolkit.widgets import Frame, TextArea
def test_split_multiline_prompt():
# Test 1: no newlines:
tokens = [("class:testclass", "ab")]
has... | 69 | 2,227 |
python-prompt-toolkit | tests/test_buffer.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.buffer import Buffer
@pytest.fixture
def _buffer():
buff = Buffer()
return buff
def test_initial(_buffer):
assert _buffer.text == ""
assert _buffer.cursor_position == 0
def test_insert_text(_buffer):
_buffer.insert_text("so... | 113 | 2,659 |
python-prompt-toolkit | tests/test_async_generator.py | .py | from __future__ import annotations
from asyncio import run
from prompt_toolkit.eventloop import generator_to_async_generator
def _sync_generator():
yield 1
yield 10
def test_generator_to_async_generator():
"""
Test conversion of sync to async generator.
This should run the synchronous parts in... | 29 | 658 |
python-prompt-toolkit | tests/test_yank_nth_arg.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.history import InMemoryHistory
@pytest.fixture
def _history():
"Prefilled history."
history = InMemoryHistory()
history.append_string("alpha beta gamma delta")
history.append_string("one two... | 87 | 2,079 |
python-prompt-toolkit | tests/test_widgets.py | .py | from __future__ import annotations
from prompt_toolkit.formatted_text import fragment_list_to_text
from prompt_toolkit.layout import to_window
from prompt_toolkit.widgets import Button
def _to_text(button: Button) -> str:
control = to_window(button).content
return fragment_list_to_text(control.text())
def ... | 21 | 554 |
python-prompt-toolkit | tests/test_vt100_output.py | .py | from __future__ import annotations
from prompt_toolkit.output.vt100 import _256_colors, _get_closest_ansi_color
def test_get_closest_ansi_color():
# White
assert _get_closest_ansi_color(255, 255, 255) == "ansiwhite"
assert _get_closest_ansi_color(250, 250, 250) == "ansiwhite"
# Black
assert _get... | 32 | 1,120 |
python-prompt-toolkit | tests/test_completion.py | .py | from __future__ import annotations
import os
import re
import shutil
import tempfile
from contextlib import contextmanager
from prompt_toolkit.completion import (
CompleteEvent,
FuzzyWordCompleter,
NestedCompleter,
PathCompleter,
WordCompleter,
merge_completers,
)
from prompt_toolkit.document ... | 470 | 15,098 |
python-prompt-toolkit | tests/test_formatted_text.py | .py | from __future__ import annotations
from prompt_toolkit.formatted_text import (
ANSI,
HTML,
FormattedText,
PygmentsTokens,
Template,
merge_formatted_text,
to_formatted_text,
)
from prompt_toolkit.formatted_text.utils import split_lines
def test_basic_html():
html = HTML("<i>hello</i>")... | 339 | 8,882 |
python-prompt-toolkit | tests/test_print_formatted_text.py | .py | """
Test the `print` function.
"""
from __future__ import annotations
import pytest
from prompt_toolkit import print_formatted_text as pt_print
from prompt_toolkit.formatted_text import HTML, FormattedText, to_formatted_text
from prompt_toolkit.output import ColorDepth
from prompt_toolkit.styles import Style
from pr... | 113 | 3,039 |
python-prompt-toolkit | tests/test_key_binding.py | .py | from __future__ import annotations
from contextlib import contextmanager
import pytest
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import set_app
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.key_binding.key_bindings import KeyBindings
... | 205 | 6,662 |
python-prompt-toolkit | tests/test_memory_leaks.py | .py | from __future__ import annotations
import gc
from prompt_toolkit.shortcuts.prompt import PromptSession
def _count_prompt_session_instances() -> int:
# Run full GC collection first.
gc.collect()
# Count number of remaining referenced `PromptSession` instances.
objects = gc.get_objects()
return l... | 33 | 872 |
python-prompt-toolkit | tests/test_layout.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.layout import InvalidLayoutError, Layout
from prompt_toolkit.layout.containers import HSplit, VSplit, Window
from prompt_toolkit.layout.controls import BufferControl
def test_layout_class():
c1 = BufferControl()
c2 = BufferControl()
c3... | 54 | 1,536 |
python-prompt-toolkit | tests/test_style_transformation.py | .py | from __future__ import annotations
import pytest
from prompt_toolkit.styles import AdjustBrightnessStyleTransformation, Attrs
@pytest.fixture
def default_attrs():
return Attrs(
color="",
bgcolor="",
bold=False,
underline=False,
strike=False,
italic=False,
... | 53 | 1,562 |
python-prompt-toolkit | tests/test_cli.py | .py | """
These are almost end-to-end tests. They create a Prompt, feed it with some
input and check the result.
"""
from __future__ import annotations
from functools import partial
import pytest
from prompt_toolkit.clipboard import ClipboardData, InMemoryClipboard
from prompt_toolkit.enums import EditingMode
from prompt... | 943 | 28,042 |
python-prompt-toolkit | tests/test_utils.py | .py | from __future__ import annotations
import itertools
import pytest
from prompt_toolkit.utils import take_using_weights
def test_using_weights():
def take(generator, count):
return list(itertools.islice(generator, 0, count))
# Check distribution.
data = take(take_using_weights(["A", "B", "C"], [... | 79 | 1,624 |
python-prompt-toolkit | tests/test_regular_languages.py | .py | from __future__ import annotations
from prompt_toolkit.completion import CompleteEvent, Completer, Completion
from prompt_toolkit.contrib.regular_languages import compile
from prompt_toolkit.contrib.regular_languages.compiler import Match, Variables
from prompt_toolkit.contrib.regular_languages.completion import Gramm... | 103 | 3,152 |
python-prompt-toolkit | examples/gevent-get-input.py | .py | #!/usr/bin/env python
"""
For testing: test to make sure that everything still works when gevent monkey
patches are applied.
"""
from gevent.monkey import patch_all
from prompt_toolkit.eventloop.defaults import create_event_loop
from prompt_toolkit.shortcuts import PromptSession
if __name__ == "__main__":
# Appl... | 26 | 685 |
python-prompt-toolkit | examples/progress-bar/colored-title-and-label.py | .py | #!/usr/bin/env python
"""
A progress bar that displays a formatted title above the progress bar and has a
colored label.
"""
import time
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import ProgressBar
def main():
title = HTML('Downloading <style bg="yellow" fg="black">4 files...<... | 24 | 538 |
python-prompt-toolkit | examples/progress-bar/unknown-length.py | .py | #!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
def data():
"""
A generator that produces items. len() doesn't work here, so the progress
bar can't estimate the time it will ... | 28 | 502 |
python-prompt-toolkit | examples/progress-bar/nested-progress-bars.py | .py | #!/usr/bin/env python
"""
Example of nested progress bars.
"""
import time
from prompt_toolkit import HTML
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar(
title=HTML('<b fg="#aa00ff">Nested progress bars</b>'),
bottom_toolbar=HTML(" <b>[Control-L]</b> clear <b>[Co... | 24 | 566 |
python-prompt-toolkit | examples/progress-bar/many-parallel-tasks.py | .py | #!/usr/bin/env python
"""
More complex demonstration of what's possible with the progress bar.
"""
import threading
import time
from prompt_toolkit import HTML
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar(
title=HTML("<b>Example of many parallel tasks.</b>"),
bot... | 48 | 1,592 |
python-prompt-toolkit | examples/progress-bar/styled-tqdm-1.py | .py | #!/usr/bin/env python
"""
Styled similar to tqdm, another progress bar implementation in Python.
See: https://github.com/noamraph/tqdm
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.styles import Style
style = Style.f... | 42 | 1,109 |
python-prompt-toolkit | examples/progress-bar/styled-tqdm-2.py | .py | #!/usr/bin/env python
"""
Styled similar to tqdm, another progress bar implementation in Python.
See: https://github.com/noamraph/tqdm
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.styles import Style
style = Style.f... | 40 | 1,035 |
python-prompt-toolkit | examples/progress-bar/two-tasks.py | .py | #!/usr/bin/env python
"""
Two progress bars that run in parallel.
"""
import threading
import time
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar() as pb:
# Two parallal tasks.
def task_1():
for i in pb(range(100)):
time.sleep(0.05)
... | 41 | 930 |
python-prompt-toolkit | examples/progress-bar/styled-2.py | .py | #!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.styles impor... | 51 | 1,347 |
python-prompt-toolkit | examples/progress-bar/styled-1.py | .py | #!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.styles import Style
style = Style.from_dict(
{
"title": "#4444ff underline",
"label": "#ff4400 bold... | 38 | 863 |
python-prompt-toolkit | examples/progress-bar/custom-key-bindings.py | .py | #!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import os
import signal
import time
from prompt_toolkit import HTML
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.patch_stdout import patch_stdout
from prompt_toolkit.shortcuts... | 53 | 1,208 |
python-prompt-toolkit | examples/progress-bar/simple-progress-bar.py | .py | #!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar() as pb:
for i in pb(range(800)):
time.sleep(0.01)
if __name__ == "__main__":
m... | 20 | 326 |
python-prompt-toolkit | examples/progress-bar/a-lot-of-parallel-tasks.py | .py | #!/usr/bin/env python
"""
More complex demonstration of what's possible with the progress bar.
"""
import random
import threading
import time
from prompt_toolkit import HTML
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar(
title=HTML("<b>Example of many parallel tasks.</b>"... | 67 | 1,902 |
python-prompt-toolkit | examples/progress-bar/scrolling-task-name.py | .py | #!/usr/bin/env python
"""
A very simple progress bar where the name of the task scrolls, because it's too long.
iterator.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
def main():
with ProgressBar(
title="Scrolling task name (make sure the window is not too big)."
) as pb:
... | 25 | 533 |
python-prompt-toolkit | examples/progress-bar/styled-apt-get-install.py | .py | #!/usr/bin/env python
"""
Styled just like an apt-get installation.
"""
import time
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.styles import Style
style = Style.from_dict(
{
"label": "bg:#ffff00 #000000",
"perc... | 40 | 942 |
python-prompt-toolkit | examples/progress-bar/styled-rainbow.py | .py | #!/usr/bin/env python
"""
A simple progress bar, visualized with rainbow colors (for fun).
"""
import time
from prompt_toolkit.output import ColorDepth
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.shortcuts.prompt import confirm
de... | 37 | 933 |
python-prompt-toolkit | examples/full-screen/text-editor.py | .py | #!/usr/bin/env python
"""
A simple example of a Notepad-like text editor.
"""
import datetime
from asyncio import Future, ensure_future
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.completion import PathCompleter
from prompt_toolkit.filt... | 382 | 9,177 |
python-prompt-toolkit | examples/full-screen/no-layout.py | .py | #!/usr/bin/env python
"""
An empty full screen application without layout.
"""
from prompt_toolkit import Application
Application(full_screen=True).run()
| 9 | 156 |
python-prompt-toolkit | examples/full-screen/calculator.py | .py | #!/usr/bin/env python
"""
A simple example of a calculator program.
This could be used as inspiration for a REPL.
"""
from prompt_toolkit.application import Application
from prompt_toolkit.document import Document
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, W... | 97 | 2,725 |
python-prompt-toolkit | examples/full-screen/full-screen-demo.py | .py | #!/usr/bin/env python
""" """
from pygments.lexers.html import HtmlLexer
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bind... | 226 | 5,606 |
python-prompt-toolkit | examples/full-screen/pager.py | .py | #!/usr/bin/env python
"""
A simple application that shows a Pager application.
"""
from pygments.lexers.python import PythonLexer
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import HSplit, Window
from prompt_toolkit.layout... | 110 | 2,442 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.