minibuffer will expand to fit contents

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-28 06:37:49 +00:00
parent f1308a4d34
commit 06deff46c3
3 changed files with 57 additions and 60 deletions

View File

@ -536,8 +536,12 @@ class Application(object):
# full screen drawer # full screen drawer
def draw(self, err=""): def draw(self, err=""):
try: try:
n = len(self.get_minibuffer_lines())
assert n > 0
if n != self.bufferlist.mini_height:
self.bufferlist.resize_mini(n)
self.draw_slots() self.draw_slots()
self.draw_input_bar() self.draw_minibuffer()
self.draw_cursor() self.draw_cursor()
self.win.refresh() self.win.refresh()
except Exception, e: except Exception, e:
@ -559,9 +563,16 @@ class Application(object):
b = self.mini_buffer b = self.mini_buffer
w = b.windows[0] w = b.windows[0]
p = w.logical_cursor() p = w.logical_cursor()
if p.y >= len(b.lines): x = p.x + len(self.mini_prompt)
y = p.y
if y >= len(b.lines):
return return
(vy, vx) = (self.y - 1, min(p.x + len(self.mini_prompt), self.x - 2))
lines = self.get_minibuffer_lines()
while x > self.x - 1:
y += 1
x -= self.x - 1
vy, vx = self.y - len(lines) + y, x
else: else:
slot = self.bufferlist.slots[self.active_slot] slot = self.bufferlist.slots[self.active_slot]
w = slot.window w = slot.window
@ -593,8 +604,7 @@ class Application(object):
try: try:
self.win.move(vy, vx) self.win.move(vy, vx)
except: except:
raise Exception, "(%d,%d==%r) was illegal (%d,%d)" % \ raise Exception, "(%r=%r) no (%r)" % ((vx, vy), p, (self.x, self.y))
(vx, vy, p, self.x, self.y)
# sub-drawing methods # sub-drawing methods
def draw_slots(self): def draw_slots(self):
@ -757,47 +767,31 @@ class Application(object):
self.win.addstr(slot.height + slot.y_offset, 0, status, curses.A_REVERSE) self.win.addstr(slot.height + slot.y_offset, 0, status, curses.A_REVERSE)
# input bar drawing # input bar drawing
def draw_input_bar(self): def draw_minibuffer(self):
if self.error_string: lines = self.get_minibuffer_lines()
self.draw_error()
elif self.mini_buffer_is_open():
self.draw_mini_buffer()
else:
self.draw_nothing()
try:
# fucking python, fucking curses, fucking fuck
self.win.addstr(self.y-1, self.x-1, ' ')
except:
pass
def _get_mini_lines(self, s):
i = self.x - 1
return [s[:i]]
lines = [s[:i]]
while i < len(s):
lines.append(s[i:self.x - 1 + i])
i += self.x - 1
return lines
def draw_error(self):
lines = self._get_mini_lines(self.error_string)
for i in range(0, len(lines)): for i in range(0, len(lines)):
line = util.pad(lines[i], self.x - 1) line = '%- *s' % (self.x - 1, lines[i])
try: try:
self.win.addstr(self.y - len(lines) + i, 0, line) self.win.addstr(self.y - len(lines) + i, 0, line)
except: except:
pass pass
def draw_mini_buffer(self): def get_minibuffer_lines(self):
b = self.mini_buffer lines, lines2 = [], []
lines = self._get_mini_lines(self.mini_prompt + b.lines[0]) if self.error_string:
for i in range(0, len(lines)): s = self.error_string
line = util.pad(lines[i], self.x - 1) elif self.mini_buffer_is_open():
self.win.addstr(self.y - len(lines) + i, 0, line) s = self.mini_prompt + self.mini_buffer.lines[0]
lines2 = self.mini_buffer.lines[1:]
def draw_nothing(self): else:
self.win.addstr(self.y-1, 0, util.pad('', self.x - 1)) return [' ' * (self.x - 1)]
i = 0
lines = []
while i < len(s):
lines.append(s[i:i + self.x - 1])
i += self.x - 1
lines.extend(lines2)
return lines
def open_aes_file(path, name=None, binary=False): def open_aes_file(path, name=None, binary=False):
if os.path.isfile(path) or not os.path.exists(path): if os.path.isfile(path) or not os.path.exists(path):

View File

@ -50,9 +50,12 @@ class BufferList(object):
offsets.insert(i, offsets[i - 1] + heights[i - 1] + 1) offsets.insert(i, offsets[i - 1] + heights[i - 1] + 1)
for i in range(0, len(self.slots)): for i in range(0, len(self.slots)):
self.slots[i].resize(heights[i], self.width, offsets[i]) self.slots[i].resize(heights[i], self.width, offsets[i])
def resize_mini(self, n):
self.mini_height = n
self.fit_slots()
def resize(self, height, width): def resize(self, height, width):
self.height = height self.height = height
self.width = width self.width = width
self.fit_slots() self.fit_slots()
def is_window_visible(self, w): def is_window_visible(self, w):

View File

@ -990,22 +990,22 @@ class SetModeTabWidth(Method):
app.modes[mode].tabwidth = vargs['width'] app.modes[mode].tabwidth = vargs['width']
w.set_error('Default tab width set to %d' % app.modes[mode].tabwidth) w.set_error('Default tab width set to %d' % app.modes[mode].tabwidth)
class HideRange(Method): #class HideRange(Method):
def _execute(self, w, **vargs): # def _execute(self, w, **vargs):
cursor = w.logical_cursor() # cursor = w.logical_cursor()
if cursor.y < w.mark.y: # if cursor.y < w.mark.y:
y1, y2 = cursor.y, w.mark.y # y1, y2 = cursor.y, w.mark.y
elif w.mark.y < cursor.y: # elif w.mark.y < cursor.y:
y1, y2 = w.mark.y, cursor.y # y1, y2 = w.mark.y, cursor.y
else: # else:
w.set_error("No line range selected") # w.set_error("No line range selected")
w.hide(y1, y2) # w.hide(y1, y2)
w.set_error("Lines %d through %d hidden" % (y1, y2)) # w.set_error("Lines %d through %d hidden" % (y1, y2))
class UnhideLine(Method): #class UnhideLine(Method):
def _execute(self, w, **vargs): # def _execute(self, w, **vargs):
cursor = w.logical_cursor() # cursor = w.logical_cursor()
if w.ishidden(cursor.y): # if w.ishidden(cursor.y):
w.unhide(cursor.y) # w.unhide(cursor.y)
w.set_error("Line %d is no longer hidden" % cursor.y) # w.set_error("Line %d is no longer hidden" % cursor.y)
else: # else:
w.set_error("Line %d is not hidden" % cursor.y) # w.set_error("Line %d is not hidden" % cursor.y)