Better handle non-iterables in color_string()
This commit is contained in:
parent
9ae8810282
commit
48eb4c13d7
1 changed files with 7 additions and 0 deletions
|
|
@ -737,6 +737,13 @@ def color_string(strings, colors, sep=' '):
|
|||
if isinstance(colors, (str, pathlib.Path)):
|
||||
colors = (colors,)
|
||||
|
||||
# Convert to strings if necessary
|
||||
try:
|
||||
iterator = iter(strings)
|
||||
except TypeError:
|
||||
# Assuming single element passed, convert to string
|
||||
strings = (str(strings),)
|
||||
|
||||
# Build new string with color escapes added
|
||||
for string, color in itertools.zip_longest(strings, colors):
|
||||
color_code = COLORS.get(color, clear_code)
|
||||
|
|
|
|||
Loading…
Reference in a new issue