minibuffer will expand to fit contents
--HG-- branch : pmacs2
This commit is contained in:
parent
f1308a4d34
commit
06deff46c3
|
@ -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,48 +767,32 @@ class Application(object):
|
|||
self.win.addstr(slot.height + slot.y_offset, 0, status, curses.A_REVERSE)
|
||||
|
||||
# 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:
|
||||
self.draw_error()
|
||||
s = self.error_string
|
||||
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:
|
||||
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]]
|
||||
return [' ' * (self.x - 1)]
|
||||
i = 0
|
||||
lines = []
|
||||
while i < len(s):
|
||||
lines.append(s[i:self.x - 1 + i])
|
||||
lines.append(s[i:i + self.x - 1])
|
||||
i += self.x - 1
|
||||
lines.extend(lines2)
|
||||
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):
|
||||
if os.path.isfile(path) or not os.path.exists(path):
|
||||
p = getpass.getpass("Please enter the AES password: ")
|
||||
|
|
|
@ -50,6 +50,9 @@ 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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue