From 48eb4c13d7b466eb618afe37ab911533855a0e92 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 2 Jan 2020 21:57:40 -0700 Subject: [PATCH] Better handle non-iterables in color_string() --- scripts/wk/std.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index ab72314a..37df3e21 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -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)