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)):
|
if isinstance(colors, (str, pathlib.Path)):
|
||||||
colors = (colors,)
|
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
|
# Build new string with color escapes added
|
||||||
for string, color in itertools.zip_longest(strings, colors):
|
for string, color in itertools.zip_longest(strings, colors):
|
||||||
color_code = COLORS.get(color, clear_code)
|
color_code = COLORS.get(color, clear_code)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue