Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"stubs/boltons",
"stubs/braintree",
"stubs/cffi",
"stubs/colorful",
"stubs/dateparser",
"stubs/defusedxml",
"stubs/docker",
Expand Down
2 changes: 2 additions & 0 deletions stubs/colorful/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "0.5.*"
upstream_repository = "https://github.com/timofurrer/colorful"
Empty file.
14 changes: 14 additions & 0 deletions stubs/colorful/colorful/ansi.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
6 changes: 6 additions & 0 deletions stubs/colorful/colorful/colors.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...
102 changes: 102 additions & 0 deletions stubs/colorful/colorful/core.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is normalized via sanitize_color_palette:

Suggested change
def colorpalette(self, colorpalette: _str | _PaletteType) -> None: ...
def colorpalette(self, colorpalette: _str | SupportsItems[str, str | tuple[int, int, int]]) -> 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: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here im a bit confused i think _PaletteType itself is updated but these should be SupportsItems[_str, | _PaletteType] ?

its not really clear right now what the issue is here 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srittau did you got the chance to look at this? I'm happily update that to be correct but right now i don't really understand how to do that

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: ...
4 changes: 4 additions & 0 deletions stubs/colorful/colorful/styles.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Final

SOLARIZED: Final[dict[str, str]]
MONOKAI: Final[dict[str, str]]
16 changes: 16 additions & 0 deletions stubs/colorful/colorful/terminal.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
2 changes: 2 additions & 0 deletions stubs/colorful/colorful/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def hex_to_rgb(value: str) -> tuple[int, int, int]: ...
def check_hex(value: str) -> None: ...