-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Initial colorful stubs #14939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial colorful stubs #14939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| version = "0.5.*" | ||
| upstream_repository = "https://github.com/timofurrer/colorful" |
| 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: ... |
| 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]]: ... |
| 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: ... | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is normalized via
Suggested change
|
||||||
| 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: ... | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here im a bit confused i think its not really clear right now what the issue is here 😕
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: ... | ||||||
| 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]] |
| 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: ... |
| 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: ... |
Uh oh!
There was an error while loading. Please reload this page.