mirror of https://github.com/Textualize/rich.git
[console][typing] Extract color-system-as-a-string to a type literal
This commit is contained in:
parent
1772458f80
commit
64dc5f1394
|
@ -522,14 +522,19 @@ def _is_jupyter() -> bool: # pragma: no cover
|
||||||
return False # Other type (?)
|
return False # Other type (?)
|
||||||
|
|
||||||
|
|
||||||
COLOR_SYSTEMS = {
|
ConsoleColorSystem = Literal["auto", "standard", "256", "truecolor", "windows"]
|
||||||
|
|
||||||
|
|
||||||
|
COLOR_SYSTEMS: Dict[ConsoleColorSystem, ColorSystem] = {
|
||||||
"standard": ColorSystem.STANDARD,
|
"standard": ColorSystem.STANDARD,
|
||||||
"256": ColorSystem.EIGHT_BIT,
|
"256": ColorSystem.EIGHT_BIT,
|
||||||
"truecolor": ColorSystem.TRUECOLOR,
|
"truecolor": ColorSystem.TRUECOLOR,
|
||||||
"windows": ColorSystem.WINDOWS,
|
"windows": ColorSystem.WINDOWS,
|
||||||
}
|
}
|
||||||
|
|
||||||
_COLOR_SYSTEMS_NAMES = {system: name for name, system in COLOR_SYSTEMS.items()}
|
_COLOR_SYSTEMS_NAMES: Dict[ColorSystem, ConsoleColorSystem] = {
|
||||||
|
system: name for name, system in COLOR_SYSTEMS.items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -619,9 +624,7 @@ class Console:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
color_system: Optional[
|
color_system: Optional[ConsoleColorSystem] = "auto",
|
||||||
Literal["auto", "standard", "256", "truecolor", "windows"]
|
|
||||||
] = "auto",
|
|
||||||
force_terminal: Optional[bool] = None,
|
force_terminal: Optional[bool] = None,
|
||||||
force_jupyter: Optional[bool] = None,
|
force_jupyter: Optional[bool] = None,
|
||||||
force_interactive: Optional[bool] = None,
|
force_interactive: Optional[bool] = None,
|
||||||
|
@ -880,11 +883,11 @@ class Console:
|
||||||
return ThemeContext(self, theme, inherit)
|
return ThemeContext(self, theme, inherit)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_system(self) -> Optional[str]:
|
def color_system(self) -> Optional[ConsoleColorSystem]:
|
||||||
"""Get color system string.
|
"""Get color system string.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Optional[str]: "standard", "256" or "truecolor".
|
Optional[ConsoleColorSystem]: "standard", "256", "truecolor" or "windows".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._color_system is not None:
|
if self._color_system is not None:
|
||||||
|
|
Loading…
Reference in New Issue