ocarina/src/plugins/cline/loop.py

104 lines
1.9 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
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.set("stdscr", stdscr)
settings.set("maxyx", maxyx)
if settings.has("prompt") == False:
settings.set("prompt", ">>> ")
else:
settings.set("prompt",settings.get("prompt")+" ")
if settings.has("maxhist") == False:
settings.set("maxhist",50)
settings.set("clinex", 0)
settings.set("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.get("stdscr").keypad(0)
curses.endwin()
# Delete keys that settings no longer needs
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.get("stdscr")
input = settings.get("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")