From 06deff46c3650750cfba0dcc2c5dcf23064b9dda Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 28 Apr 2008 06:37:49 +0000 Subject: [PATCH] minibuffer will expand to fit contents --HG-- branch : pmacs2 --- application.py | 74 +++++++++++++++++++++------------------------- bufferlist.py | 5 +++- method/__init__.py | 38 ++++++++++++------------ 3 files changed, 57 insertions(+), 60 deletions(-) diff --git a/application.py b/application.py index e1d3e71..3160040 100755 --- a/application.py +++ b/application.py @@ -536,8 +536,12 @@ class Application(object): # full screen drawer def draw(self, err=""): 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_input_bar() + self.draw_minibuffer() self.draw_cursor() self.win.refresh() except Exception, e: @@ -559,9 +563,16 @@ class Application(object): b = self.mini_buffer w = b.windows[0] 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 - (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: slot = self.bufferlist.slots[self.active_slot] w = slot.window @@ -593,8 +604,7 @@ class Application(object): try: self.win.move(vy, vx) except: - raise Exception, "(%d,%d==%r) was illegal (%d,%d)" % \ - (vx, vy, p, self.x, self.y) + raise Exception, "(%r=%r) no (%r)" % ((vx, vy), p, (self.x, self.y)) # sub-drawing methods def draw_slots(self): @@ -757,47 +767,31 @@ class Application(object): self.win.addstr(slot.height + slot.y_offset, 0, status, curses.A_REVERSE) # input bar drawing - def draw_input_bar(self): - if self.error_string: - 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) + def draw_minibuffer(self): + lines = self.get_minibuffer_lines() for i in range(0, len(lines)): - line = util.pad(lines[i], self.x - 1) + line = '%- *s' % (self.x - 1, lines[i]) try: self.win.addstr(self.y - len(lines) + i, 0, line) except: pass - def draw_mini_buffer(self): - b = self.mini_buffer - lines = self._get_mini_lines(self.mini_prompt + b.lines[0]) - for i in range(0, len(lines)): - line = util.pad(lines[i], self.x - 1) - self.win.addstr(self.y - len(lines) + i, 0, line) - - def draw_nothing(self): - self.win.addstr(self.y-1, 0, util.pad('', self.x - 1)) + def get_minibuffer_lines(self): + lines, lines2 = [], [] + if self.error_string: + s = self.error_string + elif self.mini_buffer_is_open(): + s = self.mini_prompt + self.mini_buffer.lines[0] + 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.extend(lines2) + return lines def open_aes_file(path, name=None, binary=False): if os.path.isfile(path) or not os.path.exists(path): diff --git a/bufferlist.py b/bufferlist.py index 998b47b..4a4ebf0 100644 --- a/bufferlist.py +++ b/bufferlist.py @@ -50,9 +50,12 @@ class BufferList(object): offsets.insert(i, offsets[i - 1] + heights[i - 1] + 1) for i in range(0, len(self.slots)): 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): self.height = height - self.width = width + self.width = width self.fit_slots() def is_window_visible(self, w): diff --git a/method/__init__.py b/method/__init__.py index 259ed64..c03ba5b 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -990,22 +990,22 @@ class SetModeTabWidth(Method): app.modes[mode].tabwidth = vargs['width'] w.set_error('Default tab width set to %d' % app.modes[mode].tabwidth) -class HideRange(Method): - def _execute(self, w, **vargs): - cursor = w.logical_cursor() - if cursor.y < w.mark.y: - y1, y2 = cursor.y, w.mark.y - elif w.mark.y < cursor.y: - y1, y2 = w.mark.y, cursor.y - else: - w.set_error("No line range selected") - w.hide(y1, y2) - w.set_error("Lines %d through %d hidden" % (y1, y2)) -class UnhideLine(Method): - def _execute(self, w, **vargs): - cursor = w.logical_cursor() - if w.ishidden(cursor.y): - w.unhide(cursor.y) - w.set_error("Line %d is no longer hidden" % cursor.y) - else: - w.set_error("Line %d is not hidden" % cursor.y) +#class HideRange(Method): +# def _execute(self, w, **vargs): +# cursor = w.logical_cursor() +# if cursor.y < w.mark.y: +# y1, y2 = cursor.y, w.mark.y +# elif w.mark.y < cursor.y: +# y1, y2 = w.mark.y, cursor.y +# else: +# w.set_error("No line range selected") +# w.hide(y1, y2) +# w.set_error("Lines %d through %d hidden" % (y1, y2)) +#class UnhideLine(Method): +# def _execute(self, w, **vargs): +# cursor = w.logical_cursor() +# if w.ishidden(cursor.y): +# w.unhide(cursor.y) +# w.set_error("Line %d is no longer hidden" % cursor.y) +# else: +# w.set_error("Line %d is not hidden" % cursor.y)