Skip to content

Commit

Permalink
optimize painter
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloux committed Jul 3, 2024
1 parent bbc6db8 commit ca34b80
Show file tree
Hide file tree
Showing 18 changed files with 558 additions and 571 deletions.
511 changes: 253 additions & 258 deletions termspark/painter/constants/color.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions termspark/painter/constants/fore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


class Fore(Color):
PREFIX: Final[str] = "\x1b[38;5;"
RGB_PREFIX: Final[str] = "\x1b[38;2;"
PREFIX: Final[str] = "\x1b[38;2;"
3 changes: 1 addition & 2 deletions termspark/painter/constants/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


class Highlight(Color):
PREFIX: Final[str] = "\x1b[48;5;"
RGB_PREFIX: Final[str] = "\x1b[48;2;"
PREFIX: Final[str] = "\x1b[48;2;"
8 changes: 4 additions & 4 deletions termspark/painter/painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Painter:
RESET: Final[str] = "\x1b[0m"

def __paint(self, color: str, type: Type[Color]) -> str:
if color and self.__is_rgb(color):
return f"{type.RGB_PREFIX}{color.replace(',', ';')}{self.SUFFIX}"
if hasattr(type, color.upper()):
color = getattr(type, color.upper())

if color and hasattr(type, color.upper()):
return f"{type.PREFIX}{getattr(type, color.upper())}{self.SUFFIX}"
if color and self.__is_rgb(color):
return f"{type.PREFIX}{color.replace(',', ';')}{self.SUFFIX}"

return ""

Expand Down
Loading

0 comments on commit ca34b80

Please sign in to comment.