ocarina/src/plugins/cli.py

69 lines
1.5 KiB
Python

# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 20, 2010 7:37:39 PM$"
from bt import plugin
#from bt.needle import Needle
from bt.signal import *
from bt.message import *
import cline.loop
import cline.addch
import cline.message
import cline.history
from session import settings
#import settings
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "The command line interface"
self.usage = "cli [hist, maxhist, prompt]"
def open(self):
write("Starting CLI", True)
cline.history.read()
# Register our run function and close function
register("scion-begin", cline.loop.loop)
register("scion-end", cline.loop.quit)
# Initialize a dictionary for key press inputs
settings["keyinput"] = dict()
settings["keyinput"][259] = cline.history.prev
settings["keyinput"][258] = cline.history.next
settings["keyinput"][127] = cline.addch.backspace
settings["keyinput"][10] = cline.addch.enter
def close(self):
cline.loop.quit()
cline.history.save()
write("CLI has been stopped", True)
del settings["keyinput"]
remove("scion-begin",cline.loop.loop)
remove("scion-end",cline.loop.quit)
def run(self,args):
if args==None or len(args)<1:
write(self.usage)
return
if args[0]=="prompt":
settings["prompt"] = args[1] + " "
elif args[0]=="maxhist":
if len(args) == 1:
write(settings.get("maxhist"))
else:
settings.set("maxhist",int(args[1]))
elif args[0]=="hist":
cline.history.show()
else:
write(self.usage)