diff options
Diffstat (limited to 'httpie/output/ui/palette/utils.py')
-rw-r--r-- | httpie/output/ui/palette/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/httpie/output/ui/palette/utils.py b/httpie/output/ui/palette/utils.py new file mode 100644 index 00000000..47144cbc --- /dev/null +++ b/httpie/output/ui/palette/utils.py @@ -0,0 +1,23 @@ +class ColorString(str): + def __or__(self, other: str) -> 'ColorString': + """Combine a style with a property. + + E.g: PieColor.BLUE | BOLD | ITALIC + """ + from httpie.output.ui.palette.rich import RichColor, _StyledRichColor + + if isinstance(other, str): + # In case of PieColor.BLUE | SOMETHING + # we just create a new string. + return ColorString(self + ' ' + other) + elif isinstance(other, RichColor): + # If we see a GenericColor, then we'll wrap it + # in with the desired property in a different class. + return _StyledRichColor(other, styles=self.split()) + elif isinstance(other, _StyledRichColor): + # And if it is already wrapped, we'll just extend the + # list of properties. + other.styles.extend(self.split()) + return other + else: + return NotImplemented |