1
0
Fork 0
baconscript/bs.py

42 lines
1.0 KiB
Python
Raw Normal View History

2019-11-18 13:22:31 -05:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Interactive BaconScript shell.
"""
2019-11-18 20:07:48 -05:00
import logging
2019-11-18 13:22:31 -05:00
import sys
2019-11-18 22:23:51 -05:00
from bacon.script import comment, listener
from bacon.script import loadConfig as loadBsConfig
from bacon.hog4 import HogNet
2019-11-18 13:22:31 -05:00
2019-11-18 20:07:48 -05:00
# setup logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
2019-11-18 22:23:51 -05:00
listener.osc = HogNet(loadBsConfig('server.cfg'))
2019-11-18 13:22:31 -05:00
# handle user input if run directly
if __name__ == '__main__':
if len(sys.argv) > 1:
# look for macros passed as arguments
2019-11-18 20:07:48 -05:00
logging.debug("found macro at argv[1]")
2019-11-18 13:22:31 -05:00
comment(sys.argv[1])
else:
# for input history and line editing
import readline
# be an interactive shell
while True:
# get user input
try:
text = input("comment# ")
except (KeyboardInterrupt, EOFError):
text = 'exit'
print(text)
# catch exit keyword
if text.lower() == 'exit':
break
# exec user input
comment(text)