Merge pull request #64 from dylanaraps/macos2

os: Add support for macOS (Take 2)
This commit is contained in:
Dylan Araps 2017-07-31 14:54:53 +10:00 committed by GitHub
commit 38918d0ce8
2 changed files with 21 additions and 7 deletions

View File

@ -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")

View File

@ -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]