tfscript/tfscript.py

57 lines
1.6 KiB
Python

""" Makes the configs as a massive string """
def makeCFG(cfg):
ret = ''
for key, data in cfg.items():
# I know all of these fields exist because it was verified in verify.py
bindType = firstTypeIn(data.keys())
bindContent = data[bindType]
ret += branch(key, bindContent, bindType)
return ret
def firstTypeIn(inputList):
""" Find the first element common to both lists """
types = [
"impulse",
"hold",
"toggle",
"double",
"repeat"
]
for e in types:
if e in inputList:
return e
def branch(keyName, bindContent, bindType):
if bindType == "impulse":
return impulse(keyName, bindContent)
elif bindType == "hold":
if isinstance(bindContent, str):
return simpleHold(keyName, bindContent)
else:
return listHold(keyName, bindContent)
elif bindType == "toggle":
return toggle(keyName, bindContent)
elif bindType == "double":
return double(keyName, bindContent)
elif bindType == "repeat":
return repeat(keyName, bindContent)
def impulse(key, instruction):
return f'bind {key} {instruction}\n'
def simpleHold(key, instruction):
return f'placeholder for {key} (single instruction hold)\n'
def listHold(key, options):
return f'placeholder for {key} (press and release hold)\n'
def toggle(key, options):
return f'placeholder for {key} (toggle)\n'
def double(key, options):
return f'placeholder for {key} (double)\n'
def repeat(key, options):
return f'placeholder for {key} (repeat)\n'