Skip to content

Commit

Permalink
Revert "Merge pull request #186 from JonnyDing/fix/repr-ansi-issue"
Browse files Browse the repository at this point in the history
This reverts commit 31c074d, reversing
changes made to da3d38b.
  • Loading branch information
zswang666 committed Dec 22, 2024
1 parent 31c074d commit 3201b23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
12 changes: 4 additions & 8 deletions genesis/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def _repr_elem(self, elem, common_length=0):
def _repr_elem_colorized(self, elem, common_length=0):
content = self._repr_elem(elem, common_length)
idx = content.find(">")
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{content[idx + 1:]}"
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx+1]}{formats.RESET}{content[idx+1:]}"
idx = formatted_content.find(":")
if idx >= 0:
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx + 1:]}"
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx+1:]}"
formatted_content += formats.RESET
return formatted_content

Expand Down Expand Up @@ -73,10 +73,6 @@ def _repr_brief(self):
return repr_str

def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self):
repr_str = f"{colors.BLUE}{self._repr_type()}(len={colors.MINT}{formats.UNDERLINE}{len(self)}{formats.RESET}{colors.BLUE}, ["

if len(self) == 0:
Expand Down Expand Up @@ -123,8 +119,8 @@ def __colorized__repr__(self):
right_line_len = line_len - left_line_len

repr_str = (
f"{colors.CORN}{'─' * left_line_len} {formats.BOLD}{formats.ITALIC}{header}{formats.RESET} {colors.CORN}{'─' * right_line_len}{formats.RESET}\n"
+ repr_str
f"{colors.CORN}{'─' * left_line_len} {formats.BOLD}{formats.ITALIC}{header}{formats.RESET} {colors.CORN}{'─' * right_line_len}{formats.RESET}\n"
+ repr_str
)

return repr_str
8 changes: 2 additions & 6 deletions genesis/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ def copy_attributes_from(self, options, override=False):
def _repr_type(cls):
return f"<{cls.__module__}.{cls.__qualname__}>".replace("genesis", "gs")

def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self) -> str:
def __repr__(self) -> str:
property_attrs = self.__dict__.keys()
max_attr_len = max([len(attr) for attr in property_attrs])

repr_str = f"{colors.CORN}{'─' * (max_attr_len + 3)} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * (max_attr_len + 3)}\n"
repr_str = f"{colors.CORN}{'─'*(max_attr_len + 3)} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * (max_attr_len + 3)}\n"

for attr in property_attrs:
formatted_str = f"{colors.BLUE}'{attr}'{formats.RESET}"
Expand Down
12 changes: 4 additions & 8 deletions genesis/repr_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ def _repr_brief(self):
repr_str += f", material: {self.material}"
return repr_str

def __repr__(self):
if not __debug__:
self.__colorized__repr__()

def __colorized__repr__(self) -> str:
def __repr__(self) -> str:
all_attrs = self.__dir__()
property_attrs = []

Expand All @@ -59,7 +55,7 @@ def __colorized__repr__(self) -> str:
continue
idx = content.find(">")
# format with italic and color
formatted_content = f"{colors.MINT}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{colors.MINT}{content[idx + 1:]}{formats.RESET}"
formatted_content = f"{colors.MINT}{formats.ITALIC}{content[:idx+1]}{formats.RESET}{colors.MINT}{content[idx+1:]}{formats.RESET}"
# in case it's multi-line
if isinstance(getattr(self, attr), gs.List):
# 4 = 2 x ' + : + space
Expand All @@ -85,8 +81,8 @@ def __colorized__repr__(self) -> str:
right_line_len = max(right_line_len, min_line_len)

repr_str = (
f"{colors.CORN}{'─' * left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─' * right_line_len}\n"
+ repr_str
f"{colors.CORN}{'─'*left_line_len} {formats.BOLD}{formats.ITALIC}{self._repr_type()}{formats.RESET} {colors.CORN}{'─'*right_line_len}\n"
+ repr_str
)

return repr_str
Expand Down

0 comments on commit 3201b23

Please sign in to comment.