From d6515868618d6faa02ff96b5febd7351a453a74a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 2 Jan 2018 09:34:22 +1100 Subject: colors: Cleanup --- pywal/colors.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index 394d9ee..b4ce44f 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -22,19 +22,23 @@ def imagemagick(color_count, img, magick_command): return colors.stdout.splitlines() -def gen_colors(img, color_count): - """Format the output from imagemagick into a list - of hex colors.""" +def has_im(): + """Check to see if the user has im installed.""" if shutil.which("magick"): - magick_command = ["magick", "convert"] + return ["magick", "convert"] elif shutil.which("convert"): - magick_command = ["convert"] + return ["convert"] + + print("error: imagemagick not found, exiting...\n" + "error: wal requires imagemagick to function.") + sys.exit(1) - else: - print("error: imagemagick not found, exiting...\n" - "error: wal requires imagemagick to function.") - sys.exit(1) + +def gen_colors(img, color_count): + """Format the output from imagemagick into a list + of hex colors.""" + magick_command = has_im() for index in range(0, 20, 1): raw_colors = imagemagick(color_count + index, img, magick_command) @@ -52,10 +56,7 @@ def gen_colors(img, color_count): "trying a larger palette size %s." % (color_count, color_count + index)) - # Remove the first element because it isn't a color code. - del raw_colors[0] - - return [re.search("#.{6}", str(col)).group(0) for col in raw_colors] + return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] def sort_colors(img, colors): -- cgit v1.2.3