r79051 - pyrepl/trunk/pyrepl/pyrepl
[email protected] Sat, 13 Nov 2010 01:05:08 +0100 (CET)
| Newsgroups | gmane.comp.python.pyrepl.checkins |
|---|---|
| Message-ID | <[email protected]> |
Author: antocuni
Date: Sat Nov 13 01:05:07 2010
New Revision: 79051
Modified:
pyrepl/trunk/pyrepl/pyrepl/completing_reader.py
pyrepl/trunk/pyrepl/pyrepl/readline.py
Log:
emulate readline even more, and sort completions "by column" instead of "by row"
Modified: pyrepl/trunk/pyrepl/pyrepl/completing_reader.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/completing_reader.py (original)
+++ pyrepl/trunk/pyrepl/pyrepl/completing_reader.py Sat Nov 13 01:05:07 2010
@@ -58,7 +58,7 @@
padding = maxlen - len(stripped)
return s + ' '*padding
-def build_menu(cons, wordlist, start, use_brackets):
+def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
if use_brackets:
item = "[ %s ]"
padding = 4
@@ -68,6 +68,19 @@
maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
cols = cons.width / (maxlen + padding)
rows = (len(wordlist) - 1)/cols + 1
+
+ if sort_in_column:
+ # sort_in_column=False (default) sort_in_column=True
+ # A B C A D G
+ # D E F B E
+ # G C F
+ #
+ # "fill" the table with empty words, so we always have the same amout
+ # of rows for each column
+ missing = cols*rows - len(wordlist)
+ wordlist = wordlist + ['']*missing
+ indexes = [(i%cols)*rows + i//cols for i in range(len(wordlist))]
+ wordlist = [wordlist[i] for i in indexes]
menu = []
i = start
for r in range(rows):
@@ -161,7 +174,7 @@
r.cmpltn_menu_vis = 1
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
r.console, completions, r.cmpltn_menu_end,
- r.use_brackets)
+ r.use_brackets, r.sort_in_column)
r.dirty = 1
elif stem + p in completions:
r.msg = "[ complete but not unique ]"
@@ -183,7 +196,8 @@
if w.startswith(stem)]
if completions:
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
- r.console, completions, 0, r.use_brackets)
+ r.console, completions, 0,
+ r.use_brackets, r.sort_in_column)
else:
r.cmpltn_reset()
@@ -197,6 +211,7 @@
# see the comment for the complete command
assume_immutable_completions = True
use_brackets = True # display completions inside []
+ sort_in_column = False
def collect_keymap(self):
return super(CompletingReader, self).collect_keymap() + (
Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/readline.py (original)
+++ pyrepl/trunk/pyrepl/pyrepl/readline.py Sat Nov 13 01:05:07 2010
@@ -49,6 +49,7 @@
assume_immutable_completions = False
use_brackets = False
+ sort_in_column = True
def error(self, msg="none"):
pass # don't show error messages by default
@@ -80,11 +81,7 @@
result.append(next)
state += 1
# emulate the behavior of the standard readline that sorts
- # the completions before displaying them. Note that the
- # screen order is still a bit different because pyrepl
- # displays them in this order: and readline in this one:
- # [A][B][C] A C E
- # [D][E][F] B D F
+ # the completions before displaying them.
result.sort()
return result