Skip to content

Commit 3200d18

Browse files
committed
Initial colorful stubs
1 parent 3c5531d commit 3200d18

File tree

9 files changed

+130
-0
lines changed

9 files changed

+130
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"stubs/boltons",
3131
"stubs/braintree",
3232
"stubs/cffi",
33+
"stubs/colorful",
3334
"stubs/dateparser",
3435
"stubs/defusedxml",
3536
"stubs/docker",

stubs/colorful/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "0.5.*"
2+
upstream_repository = "https://github.com/timofurrer/colorful"

stubs/colorful/colorful/__init__.pyi

Whitespace-only changes.

stubs/colorful/colorful/ansi.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MODIFIERS: dict[str, tuple[int, int]]
2+
MODIFIER_RESET_OFFSET: int
3+
FOREGROUND_COLOR_OFFSET: int
4+
BACKGROUND_COLOR_OFFSET: int
5+
COLOR_CLOSE_OFFSET: int
6+
CSI: str
7+
ANSI_ESCAPE_CODE: str
8+
NEST_PLACEHOLDER: str
9+
10+
def round(value: float) -> int: ...
11+
def rgb_to_ansi256(r: int, g: int, b: int) -> int: ...
12+
def rgb_to_ansi16(r: int, g: int, b: int, use_bright: bool = False) -> int: ...

stubs/colorful/colorful/colors.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def parse_colors(path: str) -> dict[str, str]: ...
2+
def parse_rgb_txt_file(path: str) -> dict[str, str]: ...
3+
def parse_json_color_file(path: str) -> dict[str, str]: ...
4+
def sanitize_color_palette(colorpalette: dict[str, str | tuple[int, int, int]]) -> dict[str, tuple[int, int, int]]: ...

stubs/colorful/colorful/core.pyi

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from _typeshed import SupportsWrite
2+
3+
# This module defines a function "str()", which is why "str" can't be used
4+
# as a type annotation or type alias.
5+
from builtins import str as _str
6+
from collections.abc import Iterator
7+
from typing import Any, Literal
8+
from typing_extensions import LiteralString, Self, TypeAlias
9+
10+
# Custom type helpers
11+
_ColorModeType: TypeAlias = Literal[0, 8, 16, 256, 16777215]
12+
_PaletteType: TypeAlias = dict[_str, _str | tuple[int, int, int]]
13+
_SanitizedPaletteType: TypeAlias = dict[_str, tuple[int, int, int]]
14+
_StyleType: TypeAlias = tuple[_str, _str]
15+
16+
DEFAULT_RGB_TXT_PATH: _str
17+
COLOR_PALETTE: dict[_str, _str]
18+
COLORNAMES_COLORS_PATH: _str
19+
20+
class ColorfulError(Exception): ...
21+
class ColorfulAttributeError(AttributeError, ColorfulError): ...
22+
23+
def translate_rgb_to_ansi_code(red: int, green: int, blue: int, offset: int, colormode: _ColorModeType) -> _str: ...
24+
def translate_colorname_to_ansi_code(
25+
colorname: _str, offset: int, colormode: _ColorModeType, colorpalette: _PaletteType
26+
) -> _str: ...
27+
def resolve_modifier_to_ansi_code(modifiername: _str, colormode: _ColorModeType) -> _str: ...
28+
def translate_style(style: _str, colormode: _ColorModeType, colorpalette: _PaletteType) -> _str: ...
29+
def style_string(string: _str, ansi_style: _StyleType, colormode: _ColorModeType, nested: bool = False) -> _str: ...
30+
31+
class ColorfulString:
32+
orig_string: _str
33+
styled_string: _str
34+
colorful_ctx: Colorful
35+
def __init__(self, orig_string: _str, styled_string: _str, colorful_ctx: Colorful) -> None: ...
36+
def __len__(self) -> int: ...
37+
def __iter__(self) -> Iterator[_str]: ...
38+
def __add__(self, other: _str | ColorfulString) -> Self: ...
39+
def __iadd__(self, other: _str | ColorfulString) -> Self: ...
40+
def __radd__(self, other: _str | ColorfulString) -> Self: ...
41+
def __mul__(self, other: _str) -> Self: ...
42+
def __format__(self, format_spec: _str) -> _str: ...
43+
def __getattr__(self, name: _str) -> Any: ...
44+
45+
class Colorful:
46+
NO_COLORS: int
47+
ANSI_8_COLORS: int
48+
ANSI_16_COLORS: int
49+
ANSI_256_COLORS: int
50+
TRUE_COLORS: int
51+
COLORNAMES_COLORS = COLORNAMES_COLORS_PATH
52+
close_fg_color: _str
53+
close_bg_color: _str
54+
no_bold: _str
55+
no_dimmed: _str
56+
no_italic: _str
57+
no_underlined: _str
58+
no_blinkslow: _str
59+
no_blinkrapid: _str
60+
no_inversed: _str
61+
no_concealed: _str
62+
no_struckthrough: _str
63+
colormode: _ColorModeType
64+
def __init__(self, colormode: _ColorModeType | None = None, colorpalette: _str | _PaletteType | None = None) -> None: ...
65+
@property
66+
def colorpalette(self) -> _SanitizedPaletteType | None: ...
67+
@colorpalette.setter
68+
def colorpalette(self, colorpalette: _str | _PaletteType) -> None: ...
69+
def setup(
70+
self,
71+
colormode: _ColorModeType | None = None,
72+
colorpalette: _str | _PaletteType | None = None,
73+
extend_colors: bool = False,
74+
) -> None: ...
75+
def disable(self) -> None: ...
76+
def use_8_ansi_colors(self) -> None: ...
77+
def use_16_ansi_colors(self) -> None: ...
78+
def use_256_ansi_colors(self) -> None: ...
79+
def use_true_colors(self) -> None: ...
80+
def use_palette(self, colorpalette: _str | _PaletteType) -> None: ...
81+
def update_palette(self, colorpalette: _str | _PaletteType) -> None: ...
82+
def use_style(self, style_name: _str) -> None: ...
83+
def format(self, string: _str, *args: LiteralString, **kwargs: LiteralString) -> _str: ...
84+
def str(self, string: _str) -> ColorfulString: ...
85+
def print(
86+
self, *objects: object, sep: _str = " ", end: _str = "\n", file: SupportsWrite[_str] | None = None, flush: bool = False
87+
) -> None: ...
88+
89+
class ColorfulStyle:
90+
colormode: _ColorModeType
91+
colorful_ctx: Colorful
92+
def __init__(self, style: _StyleType, colormode: _ColorModeType, colorful_ctx: Colorful) -> None: ...
93+
def evaluate(self, string: _str, nested: bool = False) -> ColorfulString: ...
94+
def __and__(self, other: Self) -> Self: ...
95+
def __call__(self, string: _str, nested: bool = False) -> ColorfulString: ...
96+
def __or__(self, other) -> ColorfulString: ...
97+
def __eq__(self, other: object) -> bool: ...
98+
def __hash__(self) -> int: ...
99+
100+
def __getattr__(self, name: _str) -> Any: ...

stubs/colorful/colorful/styles.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SOLARIZED: dict[str, str]
2+
MONOKAI: dict[str, str]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NO_COLORS: int
2+
ANSI_8_COLORS: int
3+
ANSI_16_COLORS: int
4+
ANSI_256_COLORS: int
5+
TRUE_COLORS: int
6+
7+
def detect_color_support(env: dict[str, str]) -> int: ...

stubs/colorful/colorful/utils.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hex_to_rgb(value: str) -> tuple[int, int, int]: ...
2+
def check_hex(value: str) -> None: ...

0 commit comments

Comments
 (0)