mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-10-04 08:58:44 +08:00
Initial colorful stubs (#14939)
This commit is contained in:
1 parent
b3787bc6d4
commit
901ffdc238
9 files changed
+147
No files matched your search
@@ -0,0 +1,2 @@
|
||||
version = "0.5.*"
|
||||
upstream_repository = "https://github.com/timofurrer/colorful"
|
||||
Whitespace-only changes.
@@ -0,0 +1,14 @@
|
||||
from typing import Final
|
||||
|
||||
MODIFIERS: Final[dict[str, tuple[int, int]]]
|
||||
MODIFIER_RESET_OFFSET: Final[int]
|
||||
FOREGROUND_COLOR_OFFSET: Final[int]
|
||||
BACKGROUND_COLOR_OFFSET: Final[int]
|
||||
COLOR_CLOSE_OFFSET: Final[int]
|
||||
CSI: Final[str]
|
||||
ANSI_ESCAPE_CODE: Final[str]
|
||||
NEST_PLACEHOLDER: Final[str]
|
||||
|
||||
def round(value: float) -> int: ...
|
||||
def rgb_to_ansi256(r: int, g: int, b: int) -> int: ...
|
||||
def rgb_to_ansi16(r: int, g: int, b: int, use_bright: bool = False) -> int: ...
|
||||
@@ -0,0 +1,6 @@
|
||||
from _typeshed import SupportsItems
|
||||
|
||||
def parse_colors(path: str) -> SupportsItems[str, str | tuple[int, int, int]]: ...
|
||||
def parse_rgb_txt_file(path: str) -> SupportsItems[str, str | tuple[int, int, int]]: ...
|
||||
def parse_json_color_file(path: str) -> dict[str, str]: ...
|
||||
def sanitize_color_palette(colorpalette: SupportsItems[str, str | tuple[int, int, int]]) -> dict[str, tuple[int, int, int]]: ...
|
||||
@@ -0,0 +1,102 @@
|
||||
from _typeshed import SupportsGetItem, SupportsItems, SupportsWrite
|
||||
|
||||
# This module defines a function "str()", which is why "str" can't be used
|
||||
# as a type annotation or type alias.
|
||||
from builtins import str as _str
|
||||
from collections.abc import Iterator
|
||||
from typing import Any, Final, Literal
|
||||
from typing_extensions import LiteralString, Self, TypeAlias
|
||||
|
||||
# Custom type helpers
|
||||
_ColorModeType: TypeAlias = Literal[0, 8, 16, 256, 16777215]
|
||||
_PaletteType: TypeAlias = dict[_str, _str] | dict[_str, tuple[int, int, int]] | dict[_str, _str | tuple[int, int, int]]
|
||||
_StyleType: TypeAlias = tuple[_str, _str]
|
||||
|
||||
DEFAULT_RGB_TXT_PATH: Final[_str]
|
||||
COLOR_PALETTE: Final[dict[_str, _str]]
|
||||
COLORNAMES_COLORS_PATH: Final[_str]
|
||||
|
||||
class ColorfulError(Exception): ...
|
||||
class ColorfulAttributeError(AttributeError, ColorfulError): ...
|
||||
|
||||
def translate_rgb_to_ansi_code(red: int, green: int, blue: int, offset: int, colormode: _ColorModeType) -> _str: ...
|
||||
def translate_colorname_to_ansi_code(
|
||||
colorname: _str, offset: int, colormode: _ColorModeType, colorpalette: SupportsGetItem[_str, _str | tuple[int, int, int]]
|
||||
) -> _str: ...
|
||||
def resolve_modifier_to_ansi_code(modifiername: _str, colormode: _ColorModeType) -> _str: ...
|
||||
def translate_style(
|
||||
style: _str, colormode: _ColorModeType, colorpalette: SupportsGetItem[_str, _str | tuple[int, int, int]]
|
||||
) -> _str: ...
|
||||
def style_string(string: _str, ansi_style: _StyleType, colormode: _ColorModeType, nested: bool = False) -> _str: ...
|
||||
|
||||
class ColorfulString:
|
||||
orig_string: _str
|
||||
styled_string: _str
|
||||
colorful_ctx: Colorful
|
||||
def __init__(self, orig_string: _str, styled_string: _str, colorful_ctx: Colorful) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __iter__(self) -> Iterator[_str]: ...
|
||||
def __add__(self, other: _str | ColorfulString) -> Self: ...
|
||||
def __iadd__(self, other: _str | ColorfulString) -> Self: ...
|
||||
def __radd__(self, other: _str | ColorfulString) -> Self: ...
|
||||
def __mul__(self, other: _str) -> Self: ...
|
||||
def __format__(self, format_spec: _str) -> _str: ...
|
||||
# Forwards item access to styled_string (a str).
|
||||
def __getattr__(self, name: _str) -> Any: ...
|
||||
|
||||
class Colorful:
|
||||
NO_COLORS: Final[int]
|
||||
ANSI_8_COLORS: Final[int]
|
||||
ANSI_16_COLORS: Final[int]
|
||||
ANSI_256_COLORS: Final[int]
|
||||
TRUE_COLORS: Final[int]
|
||||
COLORNAMES_COLORS = COLORNAMES_COLORS_PATH
|
||||
close_fg_color: Final[_str]
|
||||
close_bg_color: Final[_str]
|
||||
no_bold: Final[_str]
|
||||
no_dimmed: Final[_str]
|
||||
no_italic: Final[_str]
|
||||
no_underlined: Final[_str]
|
||||
no_blinkslow: Final[_str]
|
||||
no_blinkrapid: Final[_str]
|
||||
no_inversed: Final[_str]
|
||||
no_concealed: Final[_str]
|
||||
no_struckthrough: Final[_str]
|
||||
colormode: _ColorModeType
|
||||
def __init__(self, colormode: _ColorModeType | None = None, colorpalette: _str | _PaletteType | None = None) -> None: ...
|
||||
@property
|
||||
def colorpalette(self) -> SupportsItems[str, str | tuple[int, int, int]] | None: ...
|
||||
@colorpalette.setter
|
||||
def colorpalette(self, colorpalette: _str | _PaletteType) -> None: ...
|
||||
def setup(
|
||||
self,
|
||||
colormode: _ColorModeType | None = None,
|
||||
colorpalette: _str | _PaletteType | None = None,
|
||||
extend_colors: bool = False,
|
||||
) -> None: ...
|
||||
def disable(self) -> None: ...
|
||||
def use_8_ansi_colors(self) -> None: ...
|
||||
def use_16_ansi_colors(self) -> None: ...
|
||||
def use_256_ansi_colors(self) -> None: ...
|
||||
def use_true_colors(self) -> None: ...
|
||||
def use_palette(self, colorpalette: _str | _PaletteType) -> None: ...
|
||||
def update_palette(self, colorpalette: _str | _PaletteType) -> None: ...
|
||||
def use_style(self, style_name: _str) -> None: ...
|
||||
def format(self, string: _str, *args: LiteralString, **kwargs: LiteralString) -> _str: ...
|
||||
def str(self, string: _str) -> ColorfulString: ...
|
||||
def print(
|
||||
self, *objects: object, sep: _str = " ", end: _str = "\n", file: SupportsWrite[_str] | None = None, flush: bool = False
|
||||
) -> None: ...
|
||||
|
||||
class ColorfulStyle:
|
||||
colormode: _ColorModeType
|
||||
colorful_ctx: Colorful
|
||||
def __init__(self, style: _StyleType, colormode: _ColorModeType, colorful_ctx: Colorful) -> None: ...
|
||||
def evaluate(self, string: _str, nested: bool = False) -> ColorfulString: ...
|
||||
def __and__(self, other: Self) -> Self: ...
|
||||
def __call__(self, string: _str, nested: bool = False) -> ColorfulString: ...
|
||||
def __or__(self, other) -> ColorfulString: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
def __getattr__(self, name: _str) -> ColorfulStyle: ...
|
||||
@@ -0,0 +1,4 @@
|
||||
from typing import Final
|
||||
|
||||
SOLARIZED: Final[dict[str, str]]
|
||||
MONOKAI: Final[dict[str, str]]
|
||||
@@ -0,0 +1,16 @@
|
||||
from typing import Final, Protocol, overload, type_check_only
|
||||
|
||||
@type_check_only
|
||||
class _SupportsGet(Protocol):
|
||||
@overload
|
||||
def get(self, name: str, /) -> str | None: ...
|
||||
@overload
|
||||
def get(self, name: str, default: str, /) -> str: ...
|
||||
|
||||
NO_COLORS: Final[int]
|
||||
ANSI_8_COLORS: Final[int]
|
||||
ANSI_16_COLORS: Final[int]
|
||||
ANSI_256_COLORS: Final[int]
|
||||
TRUE_COLORS: Final[int]
|
||||
|
||||
def detect_color_support(env: _SupportsGet) -> int: ...
|
||||
@@ -0,0 +1,2 @@
|
||||
def hex_to_rgb(value: str) -> tuple[int, int, int]: ...
|
||||
def check_hex(value: str) -> None: ...
|
||||
Reference in new issue
Block a user