Skip to content

Commit 6f3d665

Browse files
committed
More _ApplyStyle additions
1 parent 794ddd2 commit 6f3d665

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/string_builder.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ def __str__(self):
1515
return self.style
1616

1717
def __add__(self, other):
18-
if not isinstance(other, _ApplyStyle):
18+
if not isinstance(other, (str, _ApplyStyle)):
1919
raise TypeError
20-
else:
20+
elif isinstance(other, _ApplyStyle):
2121
return _ApplyStyle(f"{self.style} {other.style}")
22+
else:
23+
return _ApplyStyle(f"{self.style} {other}")
24+
25+
def __sub__(self, other):
26+
if not isinstance(other, (str, _ApplyStyle)):
27+
raise TypeError
28+
elif isinstance(other, _ApplyStyle):
29+
return _ApplyStyle(self.style.replace(other.style, "").strip())
30+
else:
31+
return _ApplyStyle(self.style.replace(other, "").strip())
2232

2333
def apply_style(self, *strings):
2434
braces = "{}" * len(strings)

0 commit comments

Comments
 (0)