Pokemon-Terminal/adapter/implementations/ITerm.py

32 lines
876 B
Python
Raw Normal View History

import os
import subprocess
2017-06-21 11:49:16 +00:00
from adapter.base import TerminalAdapterInterface
2017-06-22 06:03:18 +00:00
# OSA script that will change the terminal background image
osa_script_fmt = """tell application "iTerm"
\ttell current session of current window
\t\tset background image to "{}"
\tend tell
end tell"""
2017-06-21 11:49:16 +00:00
class ITerm(TerminalAdapterInterface):
@staticmethod
def is_available():
return os.environ.get("ITERM_PROFILE")
def __run_osascript(self, stream):
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p.stdin.write(stream)
p.communicate()
p.stdin.close()
2017-06-21 11:49:16 +00:00
def set_pokemon(self, pokemon):
2017-06-22 06:03:18 +00:00
stdin = osa_script_fmt.format(pokemon.get_path())
self.__run_osascript(str.encode(stdin))
def clear(self):
stdin = osa_script_fmt.format("")
self.__run_osascript(str.encode(stdin))