mirror of
https://github.com/kennethreitz/crayons.git
synced 2026-06-05 23:10:18 +00:00
feat: change clean to strip ansi codes instead of all text?
This commit is contained in:
+7
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user