ocarina/src/plugins/cline/loop.py

111 lines
2.0 KiB
Python

#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Dec 19, 2009 9:39:37 PM$"
from bt.message import write
from bt.signal import *
import manager
from session import settings
# Command line related imports
from addch import addch
from message import *
global halt
halt = True
def init():
write("Beginning command line loop",True)
# Initialize ncurses screen
stdscr = curses.initscr()
maxyx = stdscr.getmaxyx()
curses.cbreak()
curses.noecho()
stdscr.keypad(1)
curses.halfdelay(10)
# Set these values in settings class for use elsewhere
settings["stdscr"] = stdscr
settings["maxyx"] = maxyx
#if settings.has("prompt") == False:
# settings.set("prompt", ">>> ")
settings.init("prompt",">>>")
settings["prompt"] += " "
#else:
# settings.set("prompt",settings.get("prompt")+" ")
#if settings.has("maxhist") == False:
# settings.set("maxhist",50)
settings.init("maxhist",50)
settings["clinex"] = 0
settings["cliney"] = 0
register("message-write", insert,90)
def quit():
# Halt our loop
global halt
if halt == True:
return
halt = True
# Undo ncurses initialization
curses.nocbreak()
curses.echo()
settings["stdscr"].keypad(0)
curses.endwin()
# Delete keys that settings no longer needs
del settings["stdscr"]
del settings["maxyx"]
del settings["cliney"]
del settings["clinex"]
#settings.delete("stdscr")
#settings.delete("maxyx")
#settings.delete("prompt")
#settings.delete("clinex")
#settings.delete("cliney")
#settings.delete("everyloop")
# Return to previous write function
remove("message-write",insert)
#settings.pop("write")
write("Command line loop has ended",True)
# Loop around until the plugin manager calls shutdown
def loop():
global halt
halt = False
init()
stdscr = settings["stdscr"]
input = settings["prompt"]
write("Type \"help\" for a list of valid commands")
disp(input)
while halt == False:
emit("cli-loop-begin")
try:
input = addch(input)
disp(input)
except:
pass
emit("cli-loop-end")