diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2022-05-05 21:17:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 11:17:12 -0700 |
commit | c4d7d05f3b6ca2e5e564e069e3a6bc500cefe54f (patch) | |
tree | f0b3ac645410f7626b533f346669983eb893a1e1 | |
parent | 7a4fb5d9661206063e0d67e3dc6e19bb7243ecb0 (diff) |
Don't make bold the default for pie themes (#1385)
-rw-r--r-- | httpie/output/ui/palette.py | 25 | ||||
-rw-r--r-- | httpie/output/ui/rich_palette.py | 30 |
2 files changed, 42 insertions, 13 deletions
diff --git a/httpie/output/ui/palette.py b/httpie/output/ui/palette.py index 2b10a0b7..5666b21f 100644 --- a/httpie/output/ui/palette.py +++ b/httpie/output/ui/palette.py @@ -1,5 +1,6 @@ +from dataclasses import dataclass, field from enum import Enum, auto -from typing import Optional +from typing import Optional, List PYGMENTS_BRIGHT_BLACK = 'ansibrightblack' @@ -34,7 +35,21 @@ class ColorString(str): 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): @@ -86,6 +101,12 @@ class GenericColor(Enum): return exposed_color +@dataclass +class _StyledGenericColor: + color: 'GenericColor' + styles: List[str] = field(default_factory=list) + + # noinspection PyDictCreation COLOR_PALETTE = { # Copy the brand palette diff --git a/httpie/output/ui/rich_palette.py b/httpie/output/ui/rich_palette.py index 3d140210..a0fc8e88 100644 --- a/httpie/output/ui/rich_palette.py +++ b/httpie/output/ui/rich_palette.py @@ -4,20 +4,22 @@ from typing import TYPE_CHECKING, Any, Optional if TYPE_CHECKING: 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 # <https://github.com/Textualize/rich/blob/fcd684dd3a482977cab620e71ccaebb94bf13ac9/rich/default_styles.py> CUSTOM_STYLES = { - 'progress.description': GenericColor.WHITE, - 'progress.data.speed': GenericColor.GREEN, - 'progress.percentage': GenericColor.AQUA, - 'progress.download': GenericColor.AQUA, - 'progress.remaining': GenericColor.ORANGE, - 'bar.complete': GenericColor.PURPLE, - 'bar.finished': GenericColor.GREEN, - 'bar.pulse': GenericColor.PURPLE, - 'option': GenericColor.PINK, + 'progress.description': RICH_BOLD | GenericColor.WHITE, + 'progress.data.speed': RICH_BOLD | GenericColor.GREEN, + 'progress.percentage': RICH_BOLD | GenericColor.AQUA, + 'progress.download': RICH_BOLD | GenericColor.AQUA, + 'progress.remaining': RICH_BOLD | GenericColor.ORANGE, + 'bar.complete': RICH_BOLD | GenericColor.PURPLE, + 'bar.finished': RICH_BOLD | GenericColor.GREEN, + 'bar.pulse': RICH_BOLD | GenericColor.PURPLE, + '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( GenericColor.__members__, CUSTOM_STYLES ).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( 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 |