better packing

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-05 17:47:12 +00:00
parent 799445eaf8
commit 3868d90ab4
1 changed files with 19 additions and 11 deletions

View File

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