mirror of
https://github.com/httpie/cli.git
synced 2024-11-29 03:03:44 +01:00
Don't make bold the default for pie themes (#1385)
This commit is contained in:
parent
7a4fb5d966
commit
c4d7d05f3b
@ -1,5 +1,6 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import Optional
|
from typing import Optional, List
|
||||||
|
|
||||||
|
|
||||||
PYGMENTS_BRIGHT_BLACK = 'ansibrightblack'
|
PYGMENTS_BRIGHT_BLACK = 'ansibrightblack'
|
||||||
@ -34,7 +35,21 @@ class ColorString(str):
|
|||||||
|
|
||||||
E.g: PieColor.BLUE | BOLD | ITALIC
|
E.g: PieColor.BLUE | BOLD | ITALIC
|
||||||
"""
|
"""
|
||||||
return ColorString(self + ' ' + other)
|
if isinstance(other, str):
|
||||||
|
# In case of PieColor.BLUE | SOMETHING
|
||||||
|
# we just create a new string.
|
||||||
|
return ColorString(self + ' ' + other)
|
||||||
|
elif isinstance(other, GenericColor):
|
||||||
|
# If we see a GenericColor, then we'll wrap it
|
||||||
|
# in with the desired property in a different class.
|
||||||
|
return _StyledGenericColor(other, styles=self.split())
|
||||||
|
elif isinstance(other, _StyledGenericColor):
|
||||||
|
# And if it is already wrapped, we'll just extend the
|
||||||
|
# list of properties.
|
||||||
|
other.styles.extend(self.split())
|
||||||
|
return other
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
class PieColor(ColorString, Enum):
|
class PieColor(ColorString, Enum):
|
||||||
@ -86,6 +101,12 @@ class GenericColor(Enum):
|
|||||||
return exposed_color
|
return exposed_color
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class _StyledGenericColor:
|
||||||
|
color: 'GenericColor'
|
||||||
|
styles: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyDictCreation
|
# noinspection PyDictCreation
|
||||||
COLOR_PALETTE = {
|
COLOR_PALETTE = {
|
||||||
# Copy the brand palette
|
# Copy the brand palette
|
||||||
|
@ -4,20 +4,22 @@ from typing import TYPE_CHECKING, Any, Optional
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from rich.theme import Theme
|
from rich.theme import Theme
|
||||||
|
|
||||||
from httpie.output.ui.palette import GenericColor, PieStyle, Styles # noqa
|
from httpie.output.ui.palette import GenericColor, PieStyle, Styles, ColorString, _StyledGenericColor # noqa
|
||||||
|
|
||||||
|
RICH_BOLD = ColorString('bold')
|
||||||
|
|
||||||
# Rich-specific color code declarations
|
# Rich-specific color code declarations
|
||||||
# <https://github.com/Textualize/rich/blob/fcd684dd3a482977cab620e71ccaebb94bf13ac9/rich/default_styles.py>
|
# <https://github.com/Textualize/rich/blob/fcd684dd3a482977cab620e71ccaebb94bf13ac9/rich/default_styles.py>
|
||||||
CUSTOM_STYLES = {
|
CUSTOM_STYLES = {
|
||||||
'progress.description': GenericColor.WHITE,
|
'progress.description': RICH_BOLD | GenericColor.WHITE,
|
||||||
'progress.data.speed': GenericColor.GREEN,
|
'progress.data.speed': RICH_BOLD | GenericColor.GREEN,
|
||||||
'progress.percentage': GenericColor.AQUA,
|
'progress.percentage': RICH_BOLD | GenericColor.AQUA,
|
||||||
'progress.download': GenericColor.AQUA,
|
'progress.download': RICH_BOLD | GenericColor.AQUA,
|
||||||
'progress.remaining': GenericColor.ORANGE,
|
'progress.remaining': RICH_BOLD | GenericColor.ORANGE,
|
||||||
'bar.complete': GenericColor.PURPLE,
|
'bar.complete': RICH_BOLD | GenericColor.PURPLE,
|
||||||
'bar.finished': GenericColor.GREEN,
|
'bar.finished': RICH_BOLD | GenericColor.GREEN,
|
||||||
'bar.pulse': GenericColor.PURPLE,
|
'bar.pulse': RICH_BOLD | GenericColor.PURPLE,
|
||||||
'option': GenericColor.PINK,
|
'option': RICH_BOLD | GenericColor.PINK,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,9 +57,15 @@ def _make_rich_color_theme(style_name: Optional[str]) -> 'Theme':
|
|||||||
for color, color_set in ChainMap(
|
for color, color_set in ChainMap(
|
||||||
GenericColor.__members__, CUSTOM_STYLES
|
GenericColor.__members__, CUSTOM_STYLES
|
||||||
).items():
|
).items():
|
||||||
|
if isinstance(color_set, _StyledGenericColor):
|
||||||
|
properties = dict.fromkeys(color_set.styles, True)
|
||||||
|
color_set = color_set.color
|
||||||
|
else:
|
||||||
|
properties = {}
|
||||||
|
|
||||||
theme.styles[color.lower()] = Style(
|
theme.styles[color.lower()] = Style(
|
||||||
color=color_set.apply_style(style, style_name=style_name),
|
color=color_set.apply_style(style, style_name=style_name),
|
||||||
bold=style is Styles.PIE,
|
**properties,
|
||||||
)
|
)
|
||||||
|
|
||||||
# E.g translate GenericColor.BLUE into blue on key access
|
# E.g translate GenericColor.BLUE into blue on key access
|
||||||
|
Loading…
Reference in New Issue
Block a user