Made it easier to add new command line keys

This commit is contained in:
bjschuma 2010-01-16 11:45:06 -05:00
parent 607c15e0b6
commit 90f363d185
2 changed files with 14 additions and 5 deletions

View File

@ -13,6 +13,7 @@ opt = []
from bt.message import *
import cline.loop
import cline.addch
import cline.message
#import settings
from bt.needle import Needle
@ -29,6 +30,11 @@ def open():
settings.set("loop",cline.loop.loop)
settings.set("loopquit",cline.loop.quit)
# Initialize a dictionary for key press inputs
settings.set("keyinput", dict())
settings.get("keyinput")[127] = cline.addch.backspace
settings.get("keyinput")[10] = cline.addch.enter
@ -38,6 +44,7 @@ def close():
#settings.pop("loopquit")()
cline.loop.quit()
write("CLI has been stopped", True)
settings.delete("keyinput")
#cline.loop.quit()

View File

@ -17,14 +17,16 @@ def addch(input):
stdscr = settings.get("stdscr")
c = stdscr.getch()
if c == 10:
input = enter(input)
#if c == 10:
# input = enter(input)
elif(c >= 32 and c<= 126):
if(c >= 32 and c<= 126):
input += curses.keyname(c)
elif c == 127:
input = backspace(input)
keys = settings.get("keyinput")
if (c in keys.keys()) == True:
input = keys[c](input)
return input