Skip to content

Commit

Permalink
Removed AnsiStr.simplify() since that is automatically done
Browse files Browse the repository at this point in the history
  • Loading branch information
James Smith authored and James Smith committed Nov 17, 2024
1 parent 0943683 commit e77780b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/ansi_string/ansi_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,7 @@ def __new__(
*settings:Union[AnsiFormat, AnsiSetting, str, int, list, tuple]
):
if isinstance(s, AnsiString):
if settings:
ansi_string = AnsiString(s, *settings)
else:
ansi_string = s
ansi_string = s
elif isinstance(s, AnsiStr):
if settings:
ansi_string = AnsiString(s, *settings)
Expand All @@ -1691,6 +1688,7 @@ def __new__(
ansi_string = AnsiString(s, *settings)
else:
raise TypeError('Invalid type for s')
ansi_string.simplify()
instance = super().__new__(cls, str(ansi_string))
instance.data = ansi_string.base_str
return instance
Expand Down Expand Up @@ -1749,10 +1747,6 @@ def __getitem__(self, val:Union[int, slice]) -> 'AnsiStr':
'''
return AnsiStr(AnsiString(str(self)).__getitem__(val))

def simplify(self):
'''Attempts to simplify formatting by re-parsing the ANSI formatting data'''
return AnsiStr(str(self))

def apply_formatting(
self,
settings:Union[AnsiFormat, AnsiSetting, str, int, list, tuple],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ansi_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def test_join_first_arg_invalid_type(self):
def test_simplify(self):
s = AnsiStr('abc', 'green')
s = s.apply_formatting('red')
s = s.simplify()
# String should automatically be simplified
self.assertEqual(str(s), '\x1b[31mabc\x1b[m')

if __name__ == '__main__':
Expand Down

0 comments on commit e77780b

Please sign in to comment.