parent
799445eaf8
commit
3868d90ab4
|
@ -233,17 +233,25 @@ class Application(object):
|
|||
|
||||
#lines = ["This is a completion buffer:", ""]
|
||||
lines = []
|
||||
if len(candidates) > self.bufferlist.slots[n].height:
|
||||
m = len(candidates) - (len(candidates) // 2)
|
||||
mlen = 0
|
||||
for c in candidates[:m]:
|
||||
mlen = max(mlen, len(c))
|
||||
for i in range(0, m):
|
||||
if m + i < len(candidates):
|
||||
c1, c2 = candidates[i * 2], candidates[i * 2 + 1]
|
||||
lines.append("%-*s %-s" % (mlen, c1, c2))
|
||||
else:
|
||||
lines.append(candidates[i * 2])
|
||||
clen = len(candidates)
|
||||
if clen > self.bufferlist.slots[n].height:
|
||||
maxlen = 0
|
||||
for c in candidates:
|
||||
maxlen = max(maxlen, len(c))
|
||||
|
||||
# NOTE: this is not an optimal packing, but it's fast and easy to
|
||||
# understand. i encourage someone else to write something better.
|
||||
numcols = self.bufferlist.slots[n].width // (maxlen + 2)
|
||||
numrows = clen - ((clen // numcols) * (numcols - 1))
|
||||
for i in range(0, numrows):
|
||||
names = []
|
||||
index = i * numcols
|
||||
for j in range(0, numcols):
|
||||
if index + j < clen:
|
||||
names.append('%-*s' % (maxlen, candidates[index + j]))
|
||||
else:
|
||||
break
|
||||
lines.append(' '.join(names))
|
||||
else:
|
||||
lines = list(candidates)
|
||||
data = '\n'.join(lines)
|
||||
|
|
Loading…
Reference in New Issue