From 93c4bcd96ba22d6ca4c759418ae841ea446c5ee7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 2 Aug 2017 19:37:55 +1000 Subject: [PATCH 1/3] colors: Create comment color based on bg. --- pywal/colors.py | 7 +++++-- pywal/util.py | 29 ++++++++++------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index 64707be..56ab095 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -61,18 +61,21 @@ def sort_colors(img, colors): if raw_colors[0][1] not in ["0", "1", "2"]: raw_colors[0] = util.darken_color(raw_colors[0], 0.25) + # Create a comment color from the background. + raw_colors[8] = util.lighten_color(raw_colors[0], 0.40) + colors = {"wallpaper": img} colors_special = {} + colors_hex = {} + colors_special.update({"background": raw_colors[0]}) colors_special.update({"foreground": raw_colors[15]}) colors_special.update({"cursor": raw_colors[15]}) - colors_hex = {} for index, color in enumerate(raw_colors): colors_hex.update({f"color{index}": color}) - colors_hex["color8"] = util.set_grey(raw_colors) colors["special"] = colors_special colors["colors"] = colors_hex diff --git a/pywal/util.py b/pywal/util.py index 2f5debc..63b5bbd 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -34,23 +34,6 @@ class Color: return f"[{self.alpha_num}]{self.hex_color}" -def set_grey(colors): - """Set a grey color based on the brightness - of another color.""" - return { - "0": "#666666", - "1": "#666666", - "2": "#757575", - "3": "#999999", - "4": "#999999", - "5": "#8a8a8a", - "6": "#a1a1a1", - "7": "#a1a1a1", - "8": "#a1a1a1", - "9": "#a1a1a1", - }.get(colors[0][1], colors[7]) - - def read_file(input_file): """Read data from a file and trim newlines.""" with open(input_file, "r") as file: @@ -114,9 +97,17 @@ def rgb_to_hex(color): return f"#{color[0]:02x}{color[1]:02x}{color[2]:02x}" -def darken_color(color, darkness): +def darken_color(color, amount): """Darken a hex color.""" - return rgb_to_hex([int(col * (1 - darkness)) for col in hex_to_rgb(color)]) + color = [int(col * (1 - amount)) for col in hex_to_rgb(color)] + print(color) + return rgb_to_hex(color) + + +def lighten_color(color, amount): + """Lighten a hex color.""" + color = [int(col + (255 - col) * amount) for col in hex_to_rgb(color)] + return rgb_to_hex(color) def disown(cmd): From af96e382b4ba65daa3f52559551209c99afa4696 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 2 Aug 2017 19:40:42 +1000 Subject: [PATCH 2/3] colors: fix print --- pywal/colors.py | 1 - pywal/util.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index 56ab095..2483acd 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -65,7 +65,6 @@ def sort_colors(img, colors): raw_colors[8] = util.lighten_color(raw_colors[0], 0.40) colors = {"wallpaper": img} - colors_special = {} colors_hex = {} diff --git a/pywal/util.py b/pywal/util.py index 63b5bbd..9931958 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -100,7 +100,6 @@ def rgb_to_hex(color): def darken_color(color, amount): """Darken a hex color.""" color = [int(col * (1 - amount)) for col in hex_to_rgb(color)] - print(color) return rgb_to_hex(color) From b0bd702454ef53afa1ada8c3f5cea74beb758866 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 2 Aug 2017 19:42:07 +1000 Subject: [PATCH 3/3] tests: Fix test --- tests/test_util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 5f8e26d..bc551ef 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -13,12 +13,6 @@ COLORS = util.read_file_json("tests/test_files/test_file.json") class TestUtil(unittest.TestCase): """Test the util functions.""" - def test_set_grey(self): - """> Get grey color based on brightness of color0""" - colors = [list(COLORS["colors"].values())] - result = util.set_grey(colors[0]) - self.assertEqual(result, "#666666") - def test_read_file(self): """> Read colors from a file.""" result = util.read_file("tests/test_files/test_file") @@ -91,6 +85,11 @@ class TestUtil(unittest.TestCase): result = util.darken_color("#ffffff", 0.25) self.assertEqual(result, "#bfbfbf") + def test_lighten_color(self): + """> Lighten #000000 by 0.25.""" + result = util.lighten_color("#000000", 0.25) + self.assertEqual(result, "#3f3f3f") + if __name__ == "__main__": unittest.main()