mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-29 22:18:49 +02:00
sequences: Send colors to macOS ttys
This commit is contained in:
parent
ca63452eb1
commit
eaf7248260
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Send sequences to all open terminals.
|
Send sequences to all open terminals.
|
||||||
"""
|
"""
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .settings import CACHE_DIR, OS
|
from .settings import CACHE_DIR, OS
|
||||||
@ -25,11 +26,11 @@ def set_color(index, color):
|
|||||||
return f"\033]4;{index};{color}\007"
|
return f"\033]4;{index};{color}\007"
|
||||||
|
|
||||||
|
|
||||||
def send(colors, vte, cache_dir=CACHE_DIR):
|
def create_sequences(colors, vte):
|
||||||
"""Send colors to all open terminals."""
|
"""Create the escape sequences."""
|
||||||
# Colors 0-15.
|
# Colors 0-15.
|
||||||
sequences = [set_color(num, color)
|
sequences = [set_color(num, col) for num, col in
|
||||||
for num, color in enumerate(colors["colors"].values())]
|
enumerate(colors["colors"].values())]
|
||||||
|
|
||||||
# Special colors.
|
# Special colors.
|
||||||
# Source: https://goo.gl/KcoQgP
|
# Source: https://goo.gl/KcoQgP
|
||||||
@ -48,12 +49,21 @@ def send(colors, vte, cache_dir=CACHE_DIR):
|
|||||||
if not vte:
|
if not vte:
|
||||||
sequences.append(set_special(708, colors["special"]["background"]))
|
sequences.append(set_special(708, colors["special"]["background"]))
|
||||||
|
|
||||||
terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
|
return "".join(sequences)
|
||||||
if len(term) < 4]
|
|
||||||
terminals.append(cache_dir / "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")
|
print("colors: Set terminal colors")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user