Set terminal colors on OpenBSD

This commit is contained in:
Ben Cornett 2020-04-11 12:26:28 -04:00
parent 1f134ac9af
commit 87194ee054

View File

@ -4,6 +4,7 @@ Send sequences to all open terminals.
import glob import glob
import logging import logging
import os import os
import subprocess
from .settings import CACHE_DIR, OS from .settings import CACHE_DIR, OS
from . import util from . import util
@ -73,17 +74,22 @@ def create_sequences(colors, vte_fix=False):
def send(colors, cache_dir=CACHE_DIR, to_send=True, vte_fix=False): def send(colors, cache_dir=CACHE_DIR, to_send=True, vte_fix=False):
"""Send colors to all open terminals.""" """Send colors to all open terminals."""
if OS == "Darwin": if OS == "Darwin":
tty_pattern = "/dev/ttys00[0-9]*" devices = glob.glob("/dev/ttys00[0-9]*")
elif OS == "OpenBSD":
devices = subprocess.check_output(
"ps -o tty | sed -e 1d -e s#^#/dev/# | sort | uniq",
shell=True,
universal_newlines=True,
).split()
else: else:
tty_pattern = "/dev/pts/[0-9]*" devices = glob.glob("/dev/pts/[0-9]*")
sequences = create_sequences(colors, vte_fix) sequences = create_sequences(colors, vte_fix)
# Writing to "/dev/pts/[0-9] lets you send data to open terminals. # Send data to open terminal devices.
if to_send: if to_send:
for term in glob.glob(tty_pattern): for dev in devices:
util.save_file(sequences, term) util.save_file(sequences, dev)
util.save_file(sequences, os.path.join(cache_dir, "sequences")) util.save_file(sequences, os.path.join(cache_dir, "sequences"))
logging.info("Set terminal colors.") logging.info("Set terminal colors.")