Better handle non-iterables in color_string()

This commit is contained in:
2Shirt 2020-01-02 21:57:40 -07:00
parent 9ae8810282
commit 48eb4c13d7
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -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)