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

View File

@ -1,4 +1,5 @@
import os
import util
# default callbacks
def none(window):
@ -29,17 +30,13 @@ def last_replace_after(window):
return None
def current_working_dir(window):
home = os.getenv('HOME')
cwd = os.getcwd()
if cwd.startswith(home):
cwd = cwd.replace(home, '~', 1)
if not cwd.endswith('/'):
cwd += '/'
return cwd
return util.normal_path(os.getcwd())
def path_dirname(window):
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
def build_constant(c):

11
util.py
View File

@ -1,5 +1,15 @@
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):
if not path.startswith('~'):
return path
@ -20,7 +30,6 @@ def expand_tilde(path):
s += '/'
return s
def cleanse(s):
s2 = s.replace("\n", "")
return s2