From ca63452eb14a4e8211ea578061973600e6b4242d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 30 Jul 2017 22:16:41 +1000 Subject: [PATCH 1/8] sequences: Send colors 0-15 --- pywal/sequences.py | 5 ++++- pywal/settings.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 4e1457d..030f030 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -3,7 +3,7 @@ Send sequences to all open terminals. """ import os -from .settings import CACHE_DIR +from .settings import CACHE_DIR, OS from . import util @@ -19,6 +19,9 @@ def set_special(index, color): def set_color(index, color): """Convert a hex color to a text color sequence.""" + if OS == "Darwin": + return f"\033]P{index:x}{color.strip('#')}\033\\" + return f"\033]4;{index};{color}\007" diff --git a/pywal/settings.py b/pywal/settings.py index 812c050..a58930a 100644 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -10,6 +10,7 @@ Created by Dylan Araps. """ import pathlib +import platform __version__ = "0.5.7" @@ -19,3 +20,4 @@ HOME = pathlib.Path.home() CACHE_DIR = HOME / ".cache/wal/" MODULE_DIR = pathlib.Path(__file__).parent COLOR_COUNT = 16 +OS = platform.uname()[0] From eaf72482608c42ceb4e90d825804451e9c9021e2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 30 Jul 2017 22:59:31 +1000 Subject: [PATCH 2/8] sequences: Send colors to macOS ttys --- pywal/sequences.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 030f030..5620b71 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -1,6 +1,7 @@ """ Send sequences to all open terminals. """ +import glob import os from .settings import CACHE_DIR, OS @@ -25,11 +26,11 @@ def set_color(index, color): return f"\033]4;{index};{color}\007" -def send(colors, vte, cache_dir=CACHE_DIR): - """Send colors to all open terminals.""" +def create_sequences(colors, vte): + """Create the escape sequences.""" # Colors 0-15. - sequences = [set_color(num, color) - for num, color in enumerate(colors["colors"].values())] + sequences = [set_color(num, col) for num, col in + enumerate(colors["colors"].values())] # Special colors. # Source: https://goo.gl/KcoQgP @@ -48,12 +49,21 @@ def send(colors, vte, cache_dir=CACHE_DIR): if not vte: sequences.append(set_special(708, colors["special"]["background"])) - terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/") - if len(term) < 4] - terminals.append(cache_dir / "sequences") + return "".join(sequences) - # Writing to "/dev/pts/[0-9] lets you send data to open terminals. - for term in terminals: - util.save_file("".join(sequences), term) +def send(colors, vte, cache_dir=CACHE_DIR): + """Send colors to all open terminals.""" + sequences = create_sequences(colors, vte) + + if OS == "Darwin": + tty_pattern = "/dev/ttys00[0-9]*" + + else: + tty_pattern = "/dev/pts/[0-9]*" + + for term in glob.glob(tty_pattern): + util.save_file(sequences, term) + + util.save_file(sequences, cache_dir / "sequences") print("colors: Set terminal colors") From dc2d5662cc3c299b4a750af92367bdb89c50077d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 30 Jul 2017 23:05:36 +1000 Subject: [PATCH 3/8] sequences: Set macOS special colors. --- pywal/sequences.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 5620b71..1deecf6 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -2,16 +2,18 @@ Send sequences to all open terminals. """ import glob -import os from .settings import CACHE_DIR, OS from . import util -def set_special(index, color): +def set_special(index, color, iterm_name): """Convert a hex color to a special sequence.""" alpha = util.Color.alpha_num + if OS == "Darwin": + return f"\033]P{iterm_name}{color.strip('#')}\033\\" + if index in [11, 708] and alpha != 100: return f"\033]{index};[{alpha}]{color}\007" @@ -36,10 +38,10 @@ def create_sequences(colors, vte): # Source: https://goo.gl/KcoQgP # 10 = foreground, 11 = background, 12 = cursor foregound # 13 = mouse foreground - sequences.append(set_special(10, colors["special"]["foreground"])) - sequences.append(set_special(11, colors["special"]["background"])) - sequences.append(set_special(12, colors["special"]["cursor"])) - sequences.append(set_special(13, colors["special"]["cursor"])) + sequences.append(set_special(10, colors["special"]["foreground"], "g")) + sequences.append(set_special(11, colors["special"]["background"], "h")) + sequences.append(set_special(12, colors["special"]["cursor"], "l")) + sequences.append(set_special(13, colors["special"]["cursor"], "l")) # Set a blank color that isn't affected by bold highlighting. # Used in wal.vim's airline theme. From a3339b3c49745f4a45dc857c74c19fb1aab3a073 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 30 Jul 2017 23:11:52 +1000 Subject: [PATCH 4/8] sequences: Add missing args --- pywal/sequences.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 1deecf6..313b093 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -7,7 +7,7 @@ from .settings import CACHE_DIR, OS from . import util -def set_special(index, color, iterm_name): +def set_special(index, color, iterm_name="g"): """Convert a hex color to a special sequence.""" alpha = util.Color.alpha_num @@ -45,7 +45,7 @@ def create_sequences(colors, vte): # Set a blank color that isn't affected by bold highlighting. # Used in wal.vim's airline theme. - sequences.append(set_color(66, colors["special"]["background"])) + sequences.append(set_color(66, colors["special"]["background"], "h")) # This escape sequence doesn"t work in VTE terminals. if not vte: From 77812341503f330563a23fda187d311c2ab3a734 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 30 Jul 2017 23:19:25 +1000 Subject: [PATCH 5/8] sequences: Fix extra arg --- pywal/sequences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 313b093..b2b1f90 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -45,7 +45,7 @@ def create_sequences(colors, vte): # Set a blank color that isn't affected by bold highlighting. # Used in wal.vim's airline theme. - sequences.append(set_color(66, colors["special"]["background"], "h")) + sequences.append(set_color(66, colors["special"]["background"])) # This escape sequence doesn"t work in VTE terminals. if not vte: From e9f98b0d1219d7cff0d03e5e21a5b2970cfc5b56 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 31 Jul 2017 01:08:26 +1000 Subject: [PATCH 6/8] tests: Fix tests --- pywal/sequences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 0c9e981..757fd95 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -63,7 +63,7 @@ def send(colors, vte, cache_dir=CACHE_DIR): else: tty_pattern = "/dev/pts/[0-9]*" - + # Writing to "/dev/pts/[0-9] lets you send data to open terminals. for term in glob.glob(tty_pattern): util.save_file(sequences, term) From bb95b278b1cc7af0759cf5861a42ad9be989cf8d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 31 Jul 2017 11:11:14 +1000 Subject: [PATCH 7/8] colors: Fix bug with brighter backgrounds --- pywal/colors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pywal/colors.py b/pywal/colors.py index 1668a13..4a55cb8 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -56,7 +56,9 @@ def sort_colors(img, colors): raw_colors = colors[:1] + colors[9:] + colors[8:] # Darken the background color if it's too light. - if int(raw_colors[0][1]) >= 3: + # The value can be a letter or an it so we treat the + # entire test as strings. + if raw_colors[0][1] not in ["0", "1", "2"]: raw_colors[0] = util.darken_color(raw_colors[0], 0.25) colors = {"wallpaper": img} From 7f49f954392e2c9a449935634a4d1f9e814bd571 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 31 Jul 2017 14:44:25 +1000 Subject: [PATCH 8/8] sequences: Fix foreground color on mac --- pywal/sequences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywal/sequences.py b/pywal/sequences.py index 757fd95..9e7a3dc 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -7,7 +7,7 @@ from .settings import CACHE_DIR, OS from . import util -def set_special(index, color, iterm_name="g"): +def set_special(index, color, iterm_name="h"): """Convert a hex color to a special sequence.""" alpha = util.Color.alpha_num