diff --git a/pywal/sequences.py b/pywal/sequences.py index e099e9e..9e7a3dc 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -3,14 +3,17 @@ Send sequences to all open terminals. """ import glob -from .settings import CACHE_DIR +from .settings import CACHE_DIR, OS from . import util -def set_special(index, color): +def set_special(index, color, iterm_name="h"): """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" @@ -19,6 +22,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" @@ -32,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. @@ -52,8 +58,14 @@ 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]*" + # Writing to "/dev/pts/[0-9] lets you send data to open terminals. - for term in glob.glob("/dev/pts/[0-9]*"): + for term in glob.glob(tty_pattern): util.save_file(sequences, term) util.save_file(sequences, cache_dir / "sequences") 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]