perl status-line improvement!

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-09 19:01:59 +00:00
parent 7f7143c491
commit 048ff560a5
3 changed files with 57 additions and 34 deletions

View File

@ -819,40 +819,7 @@ class Application(object):
slot = self.bufferlist.slots[slotname]
if slot.window is None:
return
w = slot.window
b = w.buffer
cursor = w.logical_cursor()
first = w.first
last = w.last
if b.readonly():
if b.changed():
modflag = '%*'
else:
modflag = '%%'
else:
if b.changed():
modflag = '**'
else:
modflag = '--'
if w.mark:
mark = w.mark
else:
mark = Point(-1, -1)
name = b.name()
if w.first_is_visible():
perc = "Top"
elif w.last_is_visible():
perc = "Bot"
else:
perc = "%2d%%" % (first.y*100 / len(b.lines))
# XYZ: we should actually use more of the 'state' variables
format = "%s %-18s (%s)--L%d--C%d--%s"
status = format % (modflag, name, w.mode.name(), cursor.y+1, cursor.x+1, perc)
status = slot.window.mode.get_status_bar()
status = status.ljust(slot.width)[:slot.width]
self.win.addstr(slot.height + slot.y_offset, 0, status, curses.A_REVERSE)

View File

@ -90,6 +90,7 @@ class Fundamental(Handler):
config = {}
actions = []
completers = {}
format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s"
# margin/line numbering
show_line_numbers = False
@ -254,6 +255,47 @@ class Fundamental(Handler):
def name(self):
return self.modename
def _get_flag(self):
b = self.window.buffer
if b.readonly():
if b.changed():
return '%*'
else:
return '%%'
else:
if b.changed():
return '**'
else:
return '--'
def _get_perc(self):
w = self.window
if w.first_is_visible():
return "Top"
elif w.last_is_visible():
return "Bot"
else:
return "%2d%%" % (w.first.y*100 / len(w.buffer.lines))
def _get_mark(self):
w = self.window
if w.mark:
return '(%d,%d)' % (w.mark.y + 1, w.mark.x + 1)
else:
return '(None)'
def get_status_names(self):
w = self.window
c = w.logical_cursor()
return {
'bname': w.buffer.name(),
'mname': self.name(),
'flag': self._get_flag(),
'perc': self._get_perc(),
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
'mark': self._get_mark(),
}
def get_status_bar(self):
names = self.get_status_names()
return self.format % names
# handle input tokens
def handle_token(self, t):
'''self.handle_token(token): handles input "token"'''

View File

@ -688,6 +688,20 @@ class Perl(mode.Fundamental):
completers = {
'perlfunction': PerlFunctionCompleter(),
}
format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s [%(func)s]"
def get_status_names(self):
w = self.window
c = w.logical_cursor()
names = {
'bname': w.buffer.name(),
'mname': self.name(),
'flag': self._get_flag(),
'perc': self._get_perc(),
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
'mark': self._get_mark(),
'func': self.get_line_function(c.y),
}
return names
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('perl-set-lib', ('C-c l',))