mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-11-27 06:10:29 +00:00
Defer terminal detection to the adapter itself
This commit is contained in:
parent
2fea1581c1
commit
e1ca2c8ca0
6 changed files with 48 additions and 16 deletions
|
@ -1,10 +1,14 @@
|
|||
import os
|
||||
|
||||
from adapter.implementations.ITerm import ITerm
|
||||
from adapter.implementations.NullAdapter import NullAdapter
|
||||
from adapter.implementations.Terminology import Terminology
|
||||
from adapter.implementations.Tilix import Tilix
|
||||
|
||||
available_terminals = [
|
||||
Terminology,
|
||||
Tilix,
|
||||
ITerm
|
||||
]
|
||||
|
||||
|
||||
def identify():
|
||||
"""
|
||||
|
@ -12,13 +16,8 @@ def identify():
|
|||
:return: A terminal adapter interface or a NullAdapter.
|
||||
:rtype: TerminalAdapterInterface
|
||||
"""
|
||||
if os.environ.get("TERMINOLOGY") == '1':
|
||||
return Terminology()
|
||||
|
||||
if "TILIX_ID" in os.environ:
|
||||
return Tilix()
|
||||
|
||||
if os.environ.get("ITERM_PROFILE"):
|
||||
return ITerm()
|
||||
for terminal in available_terminals:
|
||||
if terminal.is_available():
|
||||
return terminal()
|
||||
|
||||
return NullAdapter()
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
class TerminalAdapterInterface(object):
|
||||
@staticmethod
|
||||
def is_available():
|
||||
"""
|
||||
:return: True if the environment implies we are using this terminal.
|
||||
:rtype bool
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
"""
|
||||
Set the background image of the terminal.
|
||||
:param pokemon: Information about a Pokémon.
|
||||
:type pokemon: dict
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def clear(self):
|
||||
"""
|
||||
Clear the terminal's background image.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
from adapter.base import TerminalAdapterInterface
|
||||
|
||||
|
||||
class ITerm(TerminalAdapterInterface):
|
||||
@staticmethod
|
||||
def is_available():
|
||||
return os.environ.get("ITERM_PROFILE")
|
||||
|
||||
def __generate_osascript(self, path):
|
||||
# Create the content for script that will change the terminal background image.
|
||||
content = "tell application \"iTerm\"\n"
|
||||
|
@ -19,10 +24,10 @@ class ITerm(TerminalAdapterInterface):
|
|||
p.communicate()
|
||||
p.stdin.close()
|
||||
|
||||
def clear(self):
|
||||
stdin = self.__generate_osascript("")
|
||||
self.__run_osascript(str.encode(stdin))
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
stdin = self.__generate_osascript(pokemon.get_path())
|
||||
self.__run_osascript(str.encode(stdin))
|
||||
|
||||
def clear(self):
|
||||
stdin = self.__generate_osascript("")
|
||||
self.__run_osascript(str.encode(stdin))
|
||||
|
|
|
@ -4,8 +4,12 @@ from adapter.base import TerminalAdapterInterface
|
|||
class NullAdapter(TerminalAdapterInterface):
|
||||
err = "This terminal emulator is not supported."
|
||||
|
||||
def clear(self):
|
||||
print(self.err)
|
||||
@staticmethod
|
||||
def is_available():
|
||||
return True
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
print(self.err)
|
||||
|
||||
def clear(self):
|
||||
print(self.err)
|
||||
|
|
|
@ -4,6 +4,10 @@ from adapter.base import TerminalAdapterInterface
|
|||
|
||||
|
||||
class Terminology(TerminalAdapterInterface):
|
||||
@staticmethod
|
||||
def is_available():
|
||||
return os.environ.get("TERMINOLOGY") == '1'
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
os.system('tybg "{}"'.format(pokemon.get_path()))
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ class Tilix(TerminalAdapterInterface):
|
|||
setting_key = "com.gexperts.Tilix.Settings"
|
||||
setting_field = "background-image"
|
||||
|
||||
@staticmethod
|
||||
def is_available():
|
||||
return "TILIX_ID" in os.environ
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
command = 'gsettings set {} {} "{}"'
|
||||
os.system(command.format(self.setting_key,
|
||||
|
|
Loading…
Reference in a new issue