Skip to content

Commit

Permalink
refactor Painter's __paint() method
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloux committed Jul 8, 2024
1 parent f66b9cf commit 41e710a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions termspark/painter/painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ class Painter:
RESET: Final[str] = "\x1b[0m"

def __paint(self, color: Union[str, tuple], kind: Type[Color]) -> str:
if type(color) == tuple:
color = RGB.to_str(color)
color_str: str = color if type(color) == str else RGB.to_str(color)

assert type(color) == str
if hasattr(kind, color.upper()):
color = getattr(kind, color.upper())
if hasattr(kind, color_str.upper()):
color_str = getattr(kind, color_str.upper())

assert type(color) == str
color = color.replace("_", "")
if color and RGB.check(color):
return f"{kind.PREFIX}{color.replace(',', ';')}{self.SUFFIX}"
color_str = color_str.replace("_", "")
if color_str and RGB.check(color_str):
return f"{kind.PREFIX}{color_str.replace(',', ';')}{self.SUFFIX}"

return ""

Expand Down

0 comments on commit 41e710a

Please sign in to comment.