When inserted lines are greater than max number of lines, delete the

uppermost line (in the command line)
This commit is contained in:
bjschuma 2009-12-22 21:59:35 -05:00
parent 67914890f7
commit 2bd2590667
8 changed files with 67 additions and 33 deletions

View File

@ -8,14 +8,6 @@ import inspect
import settings
# Print an error message
def error(text):
lineno = str(inspect.currentframe().f_back.f_lineno)
filename = inspect.currentframe().f_back.f_code.co_filename
filename = filename.rsplit(os.sep,1)[1]
print filename,"("+lineno+"):",text
def disp(text):
print text
@ -27,4 +19,12 @@ def write(text,verbose=False):
w(text)
# Print an error message
def error(text):
lineno = str(inspect.currentframe().f_back.f_lineno)
filename = inspect.currentframe().f_back.f_code.co_filename
filename = filename.rsplit(os.sep,1)[1]
write(filename+" ("+lineno+"): "+text,True)
settings.set("write", disp)

View File

@ -38,13 +38,24 @@ def get(key, all=False):
return settings[key.upper()]
# Replace settings[key] with value
def replace(key,value):
global settings
key = key.upper()
if (key in settings) == True:
del settings[key]
set(key,value)
# Pop off the first value at key.upper()
def pop(key):
key = key.upper()
global settings
if (key in settings.keys()) == True:
return settings[key].pop(0)
return None
# Read settings from file
def readfile(file):
write("Reading file: "+file,True)
@ -56,12 +67,16 @@ def parseInput():
write("Parsing user input",True)
input = sys.argv[1:]
write(input,True)
optc = "v"
long = ["verbose"]
optc = "vp:"
long = ["verbose", "path="]
# Attempt to parse user input
try:
opts, args = getopt.getopt(input, optc, long)
for opt in opts:
if opt[0] == "-p":
set("PLUGPATH", opt[1])
set("ARGS", args)
except getopt.GetoptError, e:
error(e.msg)
return
@ -74,14 +89,14 @@ write("Setting default values...", True)
# Find who is running the program
user = os.path.expanduser("~")
user = os.path.join(user,".ocarina2")
#user = os.path.join(user,".ocarina2")
set("USER", user)
set("PLUGPATH", "../core")
# Find out what platform we are running on
set("ARCH", sys.platform)
if get("ARCH") == 'linux2':
readfile("/etc/ocarina.conf")
#if get("ARCH") == 'linux2':
# readfile("/etc/ocarina.conf")
parseInput()

View File

@ -19,44 +19,49 @@ import cline.loop
import cline.message
import settings
global maxxy, stdscr, thread
global maxyx, stdscr, thread
threads = []
# Called every time the plugin is enabled
def open():
write("Starting CLI", True)
global maxxy, stdscr, thread
global maxyx, stdscr, thread
# Initialize ncurses screen
stdscr = curses.initscr()
maxxy = stdscr.getmaxyx()
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("maxxy", maxxy)
settings.set("maxyx", maxyx)
settings.set("prompt", ">>> ")
settings.set("clinex", 0)
settings.set("cliney", 0)
settings.set("write", cline.message.insert)
# Start loop in new thread
thread = bt.needle.Needle(cline.loop.loop)
thread.start()
settings.set("write", cline.message.insert)
# Called every time the plugin is stopped
def close():
global stdscr, thread
settings.pop("write")
# Stop looping
cline.loop.quit()
# Undo ncurses initialization
curses.nocbreak()
curses.echo()
stdscr.keypad(0)
curses.endwin()
# Stop looping
cline.loop.quit()
#thread.join()
write("CLI has been stopped", True)

View File

@ -9,7 +9,7 @@ __date__ ="$Dec 19, 2009 11:19:43 PM$"
import curses
import settings
from bt.message import write
from run import run
# (Sometimes) add a character to the input string
@ -44,5 +44,6 @@ def backspace(input):
# Attempt to run a command
def enter(input):
write(input)
input = run(input)
return input

View File

@ -6,20 +6,31 @@
__author__="bjschuma"
__date__ ="$Dec 19, 2009 11:57:19 PM$"
import curses
import settings
import bt.message
# Add string to line y
def insert(string):
stdscr = settings.get("stdscr")
max = settings.get("maxyx")[0]
y = settings.get("cliney")
y+=1
settings.replace("cliney", y)
stdscr.addstr(y, 0, string)
if y < (max-1):
settings.replace("cliney", y+1)
else:
stdscr.move(0,0)
stdscr.deleteln()
# Replace the string on the current line
def disp(string):
stdscr = settings.get("stdscr")
stdscr.addstr(settings.get("cliney"), 0, string)
#insert(string, settings.get("cliney"))
try:
stdscr.addstr(settings.get("cliney"), 0, string)
except:
bt.message.error("Error displaying string: "+string)

View File

@ -8,20 +8,22 @@ __date__ ="$Dec 19, 2009 11:38:46 PM$"
from manager import manager
import settings
from bt.message import write
# Check for valid input
def run(input):
prompt = input[0:4]
input = input[4:]
split = input.strip().split()
input = input[4:].strip()
#if len(input) == 0:
# return prompt
split = input.split(' ')
if len(split)>1:
manager.run(split[0],split[1:])
else:
manager.run(input)
y = settings.get("cliney")
y+=1
settings.replace("cliney", y)
return prompt

View File

@ -7,7 +7,7 @@ rsync -avz --progress core /opt/scion/
FILE="/usr/bin/scion"
touch $FILE
echo "#!/bin/bash" > $FILE
echo "cd /opt/scion/base && \`which python\` scion.py \$\*" >> $FILE
echo "cd /opt/scion/base && \`which python\` scion.py \$*" >> $FILE
chmod +x $FILE

View File

@ -1,4 +1,4 @@
#!/bin/bash
# This is a simple shell script for properly starting ocarina
cd /opt/scion/base && `which python` scion.py $*
# This is a simple shell script for properly starting scion
cd base && `which python` scion.py $*