feat: change clean to strip ansi codes instead of all text?

This commit is contained in:
Matthew Peveler
2019-10-09 13:07:36 -03:00
parent 8133251c2d
commit a7ebd892aa
+7 -10
View File
@@ -119,16 +119,6 @@ class ColoredString(object):
return ColoredString(self.color, s)
def clean(s):
strip = re.compile(r"([^-_a-zA-Z0-9!@#%&=,/'\";:~`\$\^\*\(\)\+\[\]\.\{\}\|\?\<\>\\]+|[^\s]+)") # noqa: E501
txt = strip.sub('', str(s))
strip = re.compile(r'\[\d+m')
txt = strip.sub('', txt)
return txt
_colors = {x: x.upper() for x in COLORS}
_colors['normal'] = 'RESET'
@@ -140,6 +130,13 @@ for key, val in _colors.items():
del key, val, _colors, function
def clean(s):
strip = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]')
txt = strip.sub('', s)
return txt
def random(string, always=False, bold=False, colors=COLORS):
"""Selects a color at random from a list."""
colors = list(filter(lambda color: color in COLORS, colors)) or COLORS