general: Rename set_colors to sequences

This commit is contained in:
Dylan Araps 2017-06-30 10:15:59 +10:00
parent 930c3c8e40
commit 23571cc620
7 changed files with 52 additions and 54 deletions

View File

@ -11,7 +11,7 @@ from pywal.settings import CACHE_DIR, __version__
from pywal import export
from pywal import image
from pywal import gen_colors
from pywal import set_colors
from pywal import sequences
from pywal import reload
from pywal import wallpaper
from pywal import util
@ -79,7 +79,7 @@ def process_args(args):
# -r
if args.r:
set_colors.reload_colors(args.t)
sequences.reload_colors(args.t)
# -v
if args.v:
@ -102,7 +102,7 @@ def process_args(args):
# -i or -f
if args.i or args.f:
set_colors.send_sequences(colors_plain, args.t)
sequences.send_sequences(colors_plain, args.t)
export.export_all_templates(colors_plain)
reload.reload_env()

View File

@ -6,7 +6,6 @@ import shutil
import subprocess
from pywal.settings import CACHE_DIR, COLOR_COUNT
from pywal import set_colors
from pywal import util
@ -97,7 +96,7 @@ def sort_colors(colors):
for index, color in enumerate(raw_colors)]
# Color 8
colors_hex["color8"] = set_colors.set_grey(raw_colors)
colors_hex["color8"] = util.set_grey(raw_colors)
# Add the colors to a dict.
colors = {}

View File

@ -18,22 +18,6 @@ def set_color(index, color):
return f"\033]4;{index};{color}\007"
def set_grey(colors):
"""Set a grey color based on brightness of color0."""
return {
0: "#666666",
1: "#666666",
2: "#757575",
3: "#999999",
4: "#999999",
5: "#8a8a8a",
6: "#a1a1a1",
7: "#a1a1a1",
8: "#a1a1a1",
9: "#a1a1a1",
}.get(int(colors[0][1]), colors[7])
def send_sequences(colors, vte):
"""Send colors to all open terminals."""

View File

@ -22,6 +22,22 @@ class Color(object):
return hex_to_rgb(self.hex_color)
def set_grey(colors):
"""Set a grey color based on brightness of color0."""
return {
0: "#666666",
1: "#666666",
2: "#757575",
3: "#999999",
4: "#999999",
5: "#8a8a8a",
6: "#a1a1a1",
7: "#a1a1a1",
8: "#a1a1a1",
9: "#a1a1a1",
}.get(int(colors[0][1]), colors[7])
def read_file(input_file):
"""Read colors from a file."""
with open(input_file) as file:

26
tests/test_sequences.py Executable file
View File

@ -0,0 +1,26 @@
"""Test sequence functions."""
import unittest
from pywal import sequences
from pywal import util
# Import colors.
COLORS = util.read_file_json("tests/test_files/test_file.json")
class Testsequences(unittest.TestCase):
"""Test the sequence functions."""
def test_set_special(self):
"""> Create special escape sequence."""
result = sequences.set_special(11, COLORS["special"]["background"])
self.assertEqual(result, "\x1b]11;#3A5130\x07")
def test_set_color(self):
"""> Create color escape sequence."""
result = sequences.set_color(11, COLORS["colors"]["color0"])
self.assertEqual(result, "\033]4;11;#3A5130\007")
if __name__ == "__main__":
unittest.main()

View File

@ -1,33 +0,0 @@
"""Test set functions."""
import unittest
from pywal import set_colors
from pywal import util
# Import colors.
COLORS = util.read_file_json("tests/test_files/test_file.json")
class TestSetColors(unittest.TestCase):
"""Test the set_colors functions."""
def test_set_special(self):
"""> Create special escape sequence."""
result = set_colors.set_special(11, COLORS["special"]["background"])
self.assertEqual(result, "\x1b]11;#3A5130\x07")
def test_set_color(self):
"""> Create color escape sequence."""
result = set_colors.set_color(11, COLORS["colors"]["color0"])
self.assertEqual(result, "\033]4;11;#3A5130\007")
def test_set_grey(self):
"""> Create special escape sequence."""
colors = [list(COLORS["colors"].values())]
result = set_colors.set_grey(colors[0])
self.assertEqual(result, "#999999")
if __name__ == "__main__":
unittest.main()

View File

@ -12,6 +12,12 @@ 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, "#999999")
def test_read_file(self):
"""> Read colors from a file."""
result = util.read_file("tests/test_files/test_file")