ocarina/src/core/cline/loop.py

82 lines
1.4 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
import manager
import settings
# Command line related imports
from addch import addch
from message import *
global halt
halt = False
def init():
# Initialize ncurses screen
stdscr = curses.initscr()
maxyx = stdscr.getmaxyx()
curses.cbreak()
curses.noecho()
stdscr.keypad(1)
# Set these values in settings class for use elsewhere
settings.set("stdscr", stdscr)
settings.set("maxyx", maxyx)
settings.set("prompt", ">>> ")
settings.set("clinex", 0)
settings.set("cliney", 0)
settings.set("write", insert)
def quit():
# Halt our loop
global halt
halt = True
# Undo ncurses initialization
curses.nocbreak()
curses.echo()
settings.get("stdscr").keypad(0)
#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")
# Return to previous write function
settings.pop("write")
# Loop around until the plugin manager calls shutdown
def loop():
write("Beginning command line loop",True)
global halt
init()
stdscr = settings.get("stdscr")
input = settings.get("prompt")
(y, x) = settings.get("stdscr").getyx()
disp(input)
while halt == False:
input = addch(input)
disp(input)