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,48 +767,32 @@ 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):
lines = self.get_minibuffer_lines()
for i in range(0, len(lines)):
line = '%- *s' % (self.x - 1, lines[i])
try:
self.win.addstr(self.y - len(lines) + i, 0, line)
except:
pass
def get_minibuffer_lines(self):
lines, lines2 = [], []
if self.error_string: if self.error_string:
self.draw_error() s = self.error_string
elif self.mini_buffer_is_open(): elif self.mini_buffer_is_open():
self.draw_mini_buffer() s = self.mini_prompt + self.mini_buffer.lines[0]
lines2 = self.mini_buffer.lines[1:]
else: else:
self.draw_nothing() return [' ' * (self.x - 1)]
try: i = 0
# fucking python, fucking curses, fucking fuck lines = []
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): while i < len(s):
lines.append(s[i:self.x - 1 + i]) lines.append(s[i:i + self.x - 1])
i += self.x - 1 i += self.x - 1
lines.extend(lines2)
return lines return lines
def draw_error(self):
lines = self._get_mini_lines(self.error_string)
for i in range(0, len(lines)):
line = util.pad(lines[i], self.x - 1)
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 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):
p = getpass.getpass("Please enter the AES password: ") p = getpass.getpass("Please enter the AES password: ")

View File

@ -50,6 +50,9 @@ 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

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)