Skip to content

Commit c4d7d05

Browse files
authored
Don't make bold the default for pie themes (#1385)
1 parent 7a4fb5d commit c4d7d05

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

httpie/output/ui/palette.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from dataclasses import dataclass, field
12
from enum import Enum, auto
2-
from typing import Optional
3+
from typing import Optional, List
34

45

56
PYGMENTS_BRIGHT_BLACK = 'ansibrightblack'
@@ -34,7 +35,21 @@ def __or__(self, other: str) -> 'ColorString':
3435
3536
E.g: PieColor.BLUE | BOLD | ITALIC
3637
"""
37-
return ColorString(self + ' ' + other)
38+
if isinstance(other, str):
39+
# In case of PieColor.BLUE | SOMETHING
40+
# we just create a new string.
41+
return ColorString(self + ' ' + other)
42+
elif isinstance(other, GenericColor):
43+
# If we see a GenericColor, then we'll wrap it
44+
# in with the desired property in a different class.
45+
return _StyledGenericColor(other, styles=self.split())
46+
elif isinstance(other, _StyledGenericColor):
47+
# And if it is already wrapped, we'll just extend the
48+
# list of properties.
49+
other.styles.extend(self.split())
50+
return other
51+
else:
52+
return NotImplemented
3853

3954

4055
class PieColor(ColorString, Enum):
@@ -86,6 +101,12 @@ def apply_style(
86101
return exposed_color
87102

88103

104+
@dataclass
105+
class _StyledGenericColor:
106+
color: 'GenericColor'
107+
styles: List[str] = field(default_factory=list)
108+
109+
89110
# noinspection PyDictCreation
90111
COLOR_PALETTE = {
91112
# Copy the brand palette

httpie/output/ui/rich_palette.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
if TYPE_CHECKING:
55
from rich.theme import Theme
66

7-
from httpie.output.ui.palette import GenericColor, PieStyle, Styles # noqa
7+
from httpie.output.ui.palette import GenericColor, PieStyle, Styles, ColorString, _StyledGenericColor # noqa
8+
9+
RICH_BOLD = ColorString('bold')
810

911
# Rich-specific color code declarations
1012
# <https://github.com/Textualize/rich/blob/fcd684dd3a482977cab620e71ccaebb94bf13ac9/rich/default_styles.py>
1113
CUSTOM_STYLES = {
12-
'progress.description': GenericColor.WHITE,
13-
'progress.data.speed': GenericColor.GREEN,
14-
'progress.percentage': GenericColor.AQUA,
15-
'progress.download': GenericColor.AQUA,
16-
'progress.remaining': GenericColor.ORANGE,
17-
'bar.complete': GenericColor.PURPLE,
18-
'bar.finished': GenericColor.GREEN,
19-
'bar.pulse': GenericColor.PURPLE,
20-
'option': GenericColor.PINK,
14+
'progress.description': RICH_BOLD | GenericColor.WHITE,
15+
'progress.data.speed': RICH_BOLD | GenericColor.GREEN,
16+
'progress.percentage': RICH_BOLD | GenericColor.AQUA,
17+
'progress.download': RICH_BOLD | GenericColor.AQUA,
18+
'progress.remaining': RICH_BOLD | GenericColor.ORANGE,
19+
'bar.complete': RICH_BOLD | GenericColor.PURPLE,
20+
'bar.finished': RICH_BOLD | GenericColor.GREEN,
21+
'bar.pulse': RICH_BOLD | GenericColor.PURPLE,
22+
'option': RICH_BOLD | GenericColor.PINK,
2123
}
2224

2325

@@ -55,9 +57,15 @@ def _make_rich_color_theme(style_name: Optional[str]) -> 'Theme':
5557
for color, color_set in ChainMap(
5658
GenericColor.__members__, CUSTOM_STYLES
5759
).items():
60+
if isinstance(color_set, _StyledGenericColor):
61+
properties = dict.fromkeys(color_set.styles, True)
62+
color_set = color_set.color
63+
else:
64+
properties = {}
65+
5866
theme.styles[color.lower()] = Style(
5967
color=color_set.apply_style(style, style_name=style_name),
60-
bold=style is Styles.PIE,
68+
**properties,
6169
)
6270

6371
# E.g translate GenericColor.BLUE into blue on key access

0 commit comments

Comments
 (0)