some little stuff

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-12-04 17:16:41 +00:00
parent 793d044cac
commit 3e23f41203
3 changed files with 56 additions and 31 deletions

View File

@ -503,6 +503,11 @@ class Application(object):
def clear_error(self): def clear_error(self):
self.error_string = "" self.error_string = ""
self.error_timestamp = None self.error_timestamp = None
def try_manual_resize(self):
y, x = self.stdscr.getmaxyx()
if y != self.y or x != self.x:
self.y, self.x = y, x
self.resize_slots()
def resize_event(self): def resize_event(self):
(self.y, self.x) = self.stdscr.getmaxyx() (self.y, self.x) = self.stdscr.getmaxyx()
self.resize_slots() self.resize_slots()
@ -525,8 +530,7 @@ class Application(object):
self.kill_ring[-1] = self.kill_ring[-1] + s self.kill_ring[-1] = self.kill_ring[-1] + s
else: else:
self.kill_ring.append(s) self.kill_ring.append(s)
#if KILL_RING_LIMIT and len(self.kill_ring) > KILL_RING_LIMIT: maxnum = self.config.get('max_num_kills')
maxnum = self.config['max_num_kills']
if maxnum and len(self.kill_ring) > maxnum: if maxnum and len(self.kill_ring) > maxnum:
self.kill_ring.pop(0) self.kill_ring.pop(0)
def pop_kill(self): def pop_kill(self):
@ -589,11 +593,10 @@ class Application(object):
i = self.win.getch() i = self.win.getch()
self.resize_event() self.resize_event()
self.need_draw = True self.need_draw = True
err = ''
try: try:
self.input.parse(i) self.input.parse(i)
except Exception, e: except Exception, e:
err = str(e) self.set_error(str(e))
if self.input.tokens: if self.input.tokens:
self.need_draw = True self.need_draw = True
@ -602,7 +605,7 @@ class Application(object):
self.active_window().mode.handle_token(t) self.active_window().mode.handle_token(t)
if self.need_draw: if self.need_draw:
self.draw(err) self.draw()
self.need_draw = False self.need_draw = False
# clear the error line; it might look confusing to the user # clear the error line; it might look confusing to the user
@ -652,7 +655,7 @@ class Application(object):
self.draw() self.draw()
# full screen drawer # full screen drawer
def draw(self, err=""): def draw(self):
try: try:
n = len(self.get_minibuffer_lines()) n = len(self.get_minibuffer_lines())
assert n > 0 assert n > 0
@ -667,15 +670,14 @@ class Application(object):
# ok, so there was a problem... # ok, so there was a problem...
# let's see if the screen changed sizes and if so, resize our slots # let's see if the screen changed sizes and if so, resize our slots
self.resize_event() self.resize_event()
if err:
self.set_error(err) # clear the error message if appropriate
if (self.error_timestamp is not None and tout = self.config.get('error_timeout', 0)
self.config['error_timeout'] > 0 and tstamp = self.error_timestamp
time.time() - self.error_timestamp > self.config['error_timeout']): if tstamp and tout and time.time() - tstamp > tout:
self.clear_error() self.clear_error()
(y, x) = self.stdscr.getmaxyx()
if y != self.y or x != self.x: self.try_manual_resize()
self.resize_event()
def draw_cursor(self): def draw_cursor(self):
if self.mini_active: if self.mini_active:
@ -850,15 +852,36 @@ class Application(object):
# input bar drawing # input bar drawing
def draw_minibuffer(self): def draw_minibuffer(self):
lines = self.get_minibuffer_lines() lines = self.get_minibuffer_lines()
attr = color.build('default', 'default')
if self.error_string:
attr = color.build('default', 'default')
for i in range(0, len(lines)): for i in range(0, len(lines)):
line = '%- *s' % (self.x - 1, lines[i]) line = lines[i]
try: try:
self.win.addstr(self.y - len(lines) + i, 0, line) self.win.addstr(self.y - len(lines) + i, 0, line, attr)
except:
pass
if self.error_string or not self.mini_buffer_is_open():
return
pattr = color.build('cyan', 'default', 'bold')
plines = self.get_minibuffer_x_lines(self.mini_prompt)
for i in range(0, len(plines)):
pline = plines[i]
try:
self.win.addstr(self.y - len(lines) + i, 0, pline, pattr)
except: except:
pass pass
def get_minibuffer_x_lines(self, s):
i = 0
lines = []
while i < len(s):
lines.append(s[i:i + self.x - 1])
i += self.x - 1
return lines
def get_minibuffer_lines(self): def get_minibuffer_lines(self):
lines, lines2 = [], [] lines2 = []
if self.error_string: if self.error_string:
maxlen = self.config['max_error_len'] maxlen = self.config['max_error_len']
if len(self.error_string) < maxlen: if len(self.error_string) < maxlen:
@ -870,11 +893,7 @@ class Application(object):
lines2 = self.mini_buffer.lines[1:] lines2 = self.mini_buffer.lines[1:]
else: else:
return [' ' * (self.x - 1)] return [' ' * (self.x - 1)]
i = 0 lines = self.get_minibuffer_x_lines(s)
lines = []
while i < len(s):
lines.append(s[i:i + self.x - 1])
i += self.x - 1
lines.extend(lines2) lines.extend(lines2)
return lines return lines

View File

@ -1,4 +1,5 @@
import os import os
import util
# default callbacks # default callbacks
def none(window): def none(window):
@ -29,17 +30,13 @@ def last_replace_after(window):
return None return None
def current_working_dir(window): def current_working_dir(window):
home = os.getenv('HOME') return util.normal_path(os.getcwd())
cwd = os.getcwd()
if cwd.startswith(home):
cwd = cwd.replace(home, '~', 1)
if not cwd.endswith('/'):
cwd += '/'
return cwd
def path_dirname(window): def path_dirname(window):
if hasattr(window.buffer, 'path'): if hasattr(window.buffer, 'path'):
return os.path.dirname(window.buffer.path) + '/' return util.normal_path(window.buffer.path) + '/'
else:
return current_working_dir(window)
# default callback builders # default callback builders
def build_constant(c): def build_constant(c):

11
util.py
View File

@ -1,5 +1,15 @@
import os, pwd, regex import os, pwd, regex
def normal_path(path):
path = os.path.realpath(window.buffer.path)
home = os.getenv('HOME')
if path.startswith(home):
path = path.replace(home, '~', 1)
if os.path.isdir(path):
return path + '/'
else:
return path
def expand_tilde(path): def expand_tilde(path):
if not path.startswith('~'): if not path.startswith('~'):
return path return path
@ -20,7 +30,6 @@ def expand_tilde(path):
s += '/' s += '/'
return s return s
def cleanse(s): def cleanse(s):
s2 = s.replace("\n", "") s2 = s.replace("\n", "")
return s2 return s2