Skip to content

Commit 4b60e82

Browse files
committed
Only remove the ANSI escape codes if len_color gets a string as parameter
1 parent 0f40154 commit 4b60e82

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

progressbar/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
assert epoch
1919

2020

21-
def len_color(text):
22-
'''Return the length of text without ANSI escape codes'''
23-
return len(re.sub(u'\u001b\\[.*?[@-~]', '', text))
21+
def len_color(value):
22+
'''Return the length of `value` without ANSI escape codes'''
23+
if isinstance(value, str):
24+
value = re.sub(u'\u001b\\[.*?[@-~]', '', value)
25+
return len(value)
2426

2527

2628
class WrappingIO:

0 commit comments

Comments
 (0)