summaryrefslogtreecommitdiff
path: root/pywal/sequences.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-07-30 22:59:31 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-07-30 22:59:31 +1000
commiteaf72482608c42ceb4e90d825804451e9c9021e2 (patch)
treec770725973bd0dbcbd45084c4cf3003333b613b6 /pywal/sequences.py
parentca63452eb14a4e8211ea578061973600e6b4242d (diff)
sequences: Send colors to macOS ttys
Diffstat (limited to 'pywal/sequences.py')
-rw-r--r--pywal/sequences.py30
1 files 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)
+
+
+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 terminals:
- util.save_file("".join(sequences), term)
+ for term in glob.glob(tty_pattern):
+ util.save_file(sequences, term)
+ util.save_file(sequences, cache_dir / "sequences")
print("colors: Set terminal colors")