When inserted lines are greater than max number of lines, delete the
uppermost line (in the command line)
This commit is contained in:
parent
67914890f7
commit
2bd2590667
|
@ -8,14 +8,6 @@ import inspect
|
||||||
import settings
|
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):
|
def disp(text):
|
||||||
print text
|
print text
|
||||||
|
|
||||||
|
@ -27,4 +19,12 @@ def write(text,verbose=False):
|
||||||
w(text)
|
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)
|
settings.set("write", disp)
|
|
@ -38,13 +38,24 @@ def get(key, all=False):
|
||||||
return settings[key.upper()]
|
return settings[key.upper()]
|
||||||
|
|
||||||
|
|
||||||
|
# Replace settings[key] with value
|
||||||
def replace(key,value):
|
def replace(key,value):
|
||||||
global settings
|
global settings
|
||||||
|
key = key.upper()
|
||||||
if (key in settings) == True:
|
if (key in settings) == True:
|
||||||
del settings[key]
|
del settings[key]
|
||||||
set(key,value)
|
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
|
# Read settings from file
|
||||||
def readfile(file):
|
def readfile(file):
|
||||||
write("Reading file: "+file,True)
|
write("Reading file: "+file,True)
|
||||||
|
@ -56,12 +67,16 @@ def parseInput():
|
||||||
write("Parsing user input",True)
|
write("Parsing user input",True)
|
||||||
input = sys.argv[1:]
|
input = sys.argv[1:]
|
||||||
write(input,True)
|
write(input,True)
|
||||||
optc = "v"
|
optc = "vp:"
|
||||||
long = ["verbose"]
|
long = ["verbose", "path="]
|
||||||
|
|
||||||
# Attempt to parse user input
|
# Attempt to parse user input
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(input, optc, long)
|
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:
|
except getopt.GetoptError, e:
|
||||||
error(e.msg)
|
error(e.msg)
|
||||||
return
|
return
|
||||||
|
@ -74,14 +89,14 @@ write("Setting default values...", True)
|
||||||
|
|
||||||
# Find who is running the program
|
# Find who is running the program
|
||||||
user = os.path.expanduser("~")
|
user = os.path.expanduser("~")
|
||||||
user = os.path.join(user,".ocarina2")
|
#user = os.path.join(user,".ocarina2")
|
||||||
set("USER", user)
|
set("USER", user)
|
||||||
set("PLUGPATH", "../core")
|
set("PLUGPATH", "../core")
|
||||||
|
|
||||||
# Find out what platform we are running on
|
# Find out what platform we are running on
|
||||||
set("ARCH", sys.platform)
|
set("ARCH", sys.platform)
|
||||||
|
|
||||||
if get("ARCH") == 'linux2':
|
#if get("ARCH") == 'linux2':
|
||||||
readfile("/etc/ocarina.conf")
|
# readfile("/etc/ocarina.conf")
|
||||||
|
|
||||||
parseInput()
|
parseInput()
|
|
@ -19,44 +19,49 @@ import cline.loop
|
||||||
import cline.message
|
import cline.message
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
global maxxy, stdscr, thread
|
global maxyx, stdscr, thread
|
||||||
threads = []
|
threads = []
|
||||||
|
|
||||||
|
|
||||||
# Called every time the plugin is enabled
|
# Called every time the plugin is enabled
|
||||||
def open():
|
def open():
|
||||||
write("Starting CLI", True)
|
write("Starting CLI", True)
|
||||||
global maxxy, stdscr, thread
|
global maxyx, stdscr, thread
|
||||||
# Initialize ncurses screen
|
# Initialize ncurses screen
|
||||||
stdscr = curses.initscr()
|
stdscr = curses.initscr()
|
||||||
maxxy = stdscr.getmaxyx()
|
maxyx = stdscr.getmaxyx()
|
||||||
curses.cbreak()
|
curses.cbreak()
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
stdscr.keypad(1)
|
stdscr.keypad(1)
|
||||||
|
|
||||||
# Set these values in settings class for use elsewhere
|
# Set these values in settings class for use elsewhere
|
||||||
settings.set("stdscr", stdscr)
|
settings.set("stdscr", stdscr)
|
||||||
settings.set("maxxy", maxxy)
|
settings.set("maxyx", maxyx)
|
||||||
settings.set("prompt", ">>> ")
|
settings.set("prompt", ">>> ")
|
||||||
settings.set("clinex", 0)
|
settings.set("clinex", 0)
|
||||||
settings.set("cliney", 0)
|
settings.set("cliney", 0)
|
||||||
settings.set("write", cline.message.insert)
|
|
||||||
|
|
||||||
# Start loop in new thread
|
# Start loop in new thread
|
||||||
thread = bt.needle.Needle(cline.loop.loop)
|
thread = bt.needle.Needle(cline.loop.loop)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
settings.set("write", cline.message.insert)
|
||||||
|
|
||||||
|
|
||||||
# Called every time the plugin is stopped
|
# Called every time the plugin is stopped
|
||||||
def close():
|
def close():
|
||||||
global stdscr, thread
|
global stdscr, thread
|
||||||
|
|
||||||
|
settings.pop("write")
|
||||||
|
|
||||||
|
# Stop looping
|
||||||
|
cline.loop.quit()
|
||||||
|
|
||||||
# Undo ncurses initialization
|
# Undo ncurses initialization
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
curses.echo()
|
curses.echo()
|
||||||
stdscr.keypad(0)
|
stdscr.keypad(0)
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
# Stop looping
|
|
||||||
cline.loop.quit()
|
|
||||||
#thread.join()
|
#thread.join()
|
||||||
write("CLI has been stopped", True)
|
write("CLI has been stopped", True)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ __date__ ="$Dec 19, 2009 11:19:43 PM$"
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
import settings
|
import settings
|
||||||
|
from bt.message import write
|
||||||
from run import run
|
from run import run
|
||||||
|
|
||||||
# (Sometimes) add a character to the input string
|
# (Sometimes) add a character to the input string
|
||||||
|
@ -44,5 +44,6 @@ def backspace(input):
|
||||||
|
|
||||||
# Attempt to run a command
|
# Attempt to run a command
|
||||||
def enter(input):
|
def enter(input):
|
||||||
|
write(input)
|
||||||
input = run(input)
|
input = run(input)
|
||||||
return input
|
return input
|
|
@ -6,20 +6,31 @@
|
||||||
__author__="bjschuma"
|
__author__="bjschuma"
|
||||||
__date__ ="$Dec 19, 2009 11:57:19 PM$"
|
__date__ ="$Dec 19, 2009 11:57:19 PM$"
|
||||||
|
|
||||||
|
|
||||||
|
import curses
|
||||||
import settings
|
import settings
|
||||||
|
import bt.message
|
||||||
|
|
||||||
|
|
||||||
# Add string to line y
|
# Add string to line y
|
||||||
def insert(string):
|
def insert(string):
|
||||||
stdscr = settings.get("stdscr")
|
stdscr = settings.get("stdscr")
|
||||||
|
max = settings.get("maxyx")[0]
|
||||||
y = settings.get("cliney")
|
y = settings.get("cliney")
|
||||||
y+=1
|
|
||||||
settings.replace("cliney", y)
|
|
||||||
stdscr.addstr(y, 0, string)
|
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
|
# Replace the string on the current line
|
||||||
def disp(string):
|
def disp(string):
|
||||||
stdscr = settings.get("stdscr")
|
stdscr = settings.get("stdscr")
|
||||||
stdscr.addstr(settings.get("cliney"), 0, string)
|
try:
|
||||||
#insert(string, settings.get("cliney"))
|
stdscr.addstr(settings.get("cliney"), 0, string)
|
||||||
|
except:
|
||||||
|
bt.message.error("Error displaying string: "+string)
|
||||||
|
|
|
@ -8,20 +8,22 @@ __date__ ="$Dec 19, 2009 11:38:46 PM$"
|
||||||
|
|
||||||
from manager import manager
|
from manager import manager
|
||||||
import settings
|
import settings
|
||||||
|
from bt.message import write
|
||||||
|
|
||||||
|
|
||||||
# Check for valid input
|
# Check for valid input
|
||||||
def run(input):
|
def run(input):
|
||||||
prompt = input[0:4]
|
prompt = input[0:4]
|
||||||
input = input[4:]
|
input = input[4:].strip()
|
||||||
split = input.strip().split()
|
|
||||||
|
#if len(input) == 0:
|
||||||
|
# return prompt
|
||||||
|
|
||||||
|
split = input.split(' ')
|
||||||
if len(split)>1:
|
if len(split)>1:
|
||||||
manager.run(split[0],split[1:])
|
manager.run(split[0],split[1:])
|
||||||
else:
|
else:
|
||||||
manager.run(input)
|
manager.run(input)
|
||||||
|
|
||||||
y = settings.get("cliney")
|
|
||||||
y+=1
|
|
||||||
settings.replace("cliney", y)
|
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
|
|
|
@ -7,7 +7,7 @@ rsync -avz --progress core /opt/scion/
|
||||||
FILE="/usr/bin/scion"
|
FILE="/usr/bin/scion"
|
||||||
touch $FILE
|
touch $FILE
|
||||||
echo "#!/bin/bash" > $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
|
chmod +x $FILE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue