nicer application options

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-24 03:35:02 +00:00
parent 79e7ba97b0
commit 7293d9d916
2 changed files with 28 additions and 5 deletions

View File

@ -11,7 +11,7 @@ import mode, util, window
from point import Point
class Application(object):
def __init__(self, stdscr, buffers=[], jump_to_line=None, init_mode=None):
def __init__(self, stdscr, buffers=[], **kwargs):
# initalize curses primitives
self.stdscr = stdscr
self.y, self.x = self.stdscr.getmaxyx()
@ -149,11 +149,12 @@ class Application(object):
if b.modename:
window.Window(b, self)
else:
window.Window(b, self, mode_name=init_mode)
window.Window(b, self, mode_name=kwargs.get('init_mode'))
self.bufferlist.add_buffer(b)
self.bufferlist.set_slot(self.active_slot, buffers[0])
# see if the user has requested that we go to a particular line
jump_to_line = kwargs.get('jump_to_line')
if not self.rcerror and jump_to_line:
w = self.bufferlist.slots[0].window
self.methods['goto-line'].execute(w, lineno=jump_to_line)
@ -941,9 +942,13 @@ def open_plain_file(path, name=None, binary=False):
else:
raise Exception, "can't open %r; unsupported file type" % path
def run_app(stdscr, buffers, jump_to_line=None, init_mode=None):
def run_app(stdscr, buffers, **kwargs):
curses.def_shell_mode()
a = Application(stdscr, buffers, jump_to_line, init_mode)
a = Application(stdscr, buffers, **kwargs)
if kwargs.get('init_cmd'):
act = a.methods[kwargs['init_cmd']]
act.execute(a.active_window())
a.last_action = act.name
a.run()
return 0
@ -985,6 +990,8 @@ if __name__ == "__main__":
help='jump to line NUM of the first argument')
parser.add_option('-m', '--mode', dest='mode', metavar='MODE',
help='open arguments in MODE')
parser.add_option('-x', '--exec', dest='cmd', metavar='CMD',
help='run CMD after launching')
(opts, args) = parser.parse_args(argv)
@ -1044,7 +1051,9 @@ if __name__ == "__main__":
# ok, now run our app
try:
curses.wrapper(run_app, buffers, opts.goto, opts.mode)
d = {'jump_to_line': opts.goto, 'init_mode': opts.mode,
'init_cmd': opts.cmd}
curses.wrapper(run_app, buffers, **d)
err = 0
except:
traceback.print_exc()

14
term.py
View File

@ -24,6 +24,16 @@ class Dumb:
self.outs = ''
self.i = 0
self.outc = []
def term_do_clear_bol(self):
pass
def term_do_clear_eol(self):
try:
del self.outc[self.i:]
except:
raise Exception(str(dir(self)))
def term_do_clear_eos(self):
pass
def term_do_backspace(self):
self.i = max(0, self.i - 1)
def term_do_tab(self):
@ -108,6 +118,10 @@ class XTerm(Dumb):
'smso': 'term_nop', #enter standout mode
'rmso': 'term_nop',
'cup': 'term_nop',
#'ed': 'term_nop',
'el': 'term_do_clear_eol',
#'el1': 'term_nop',
}
def __init__(self):
self._meta = []