From 3d1f11b1bd70b17567808849fd9eb3346599bb53 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 21 Jul 2017 11:19:17 +1000 Subject: [PATCH] util: Add new msg function. --- pywal/magic.py | 9 ++------- pywal/util.py | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pywal/magic.py b/pywal/magic.py index 3443113..9dc528c 100644 --- a/pywal/magic.py +++ b/pywal/magic.py @@ -69,9 +69,7 @@ def get_colors(img, cache_dir, color_count, quiet): print("colors: Found cached colorscheme.") else: - print("colors: Generating a colorscheme...") - if not quiet: - util.disown("notify-send", "wal: Generating a colorscheme...") + util.msg("wal: Generating a colorscheme...", quiet) # Generate the colors. colors = gen_colors(img, color_count) @@ -79,10 +77,7 @@ def get_colors(img, cache_dir, color_count, quiet): # Cache the colorscheme. util.save_file_json(colors, cache_file) - - print("colors: Generated colorscheme") - if not quiet: - util.disown("notify-send", "wal: Generation complete.") + util.msg("wal: Generation complete.", quiet) return colors diff --git a/pywal/util.py b/pywal/util.py index 6c5b420..1030b60 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -98,3 +98,12 @@ def disown(*cmd): stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, preexec_fn=os.setpgrp) + + +def msg(input_msg, quiet): + """Print to the terminal and a libnotify + notification.""" + if not quiet: + disown("notify-send", input_msg) + + print(input_msg)