Skip to content

Commit 34eb9ac

Browse files
committed
Show only key in list of dictionary key suggestions.
1 parent 37906c0 commit 34eb9ac

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

bpython/cli.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,15 +1277,22 @@ def show_list(self, items, topline=None, current_item=None):
12771277
max_h = y + 1
12781278
max_w = int(w * self.config.cli_suggestion_width)
12791279
self.list_win.erase()
1280+
12801281
if items:
12811282
sep = '.'
1282-
if os.path.sep in items[0]:
1283-
# Filename completion
1284-
sep = os.path.sep
1285-
if sep in items[0]:
1286-
items = [x.rstrip(sep).rsplit(sep)[-1] for x in items]
1283+
separators = ['.', os.path.sep, '[']
1284+
lastindex = max([items[0].rfind(c) for c in separators])
1285+
if lastindex > -1:
1286+
sep = items[0][lastindex]
1287+
items = [x.rstrip(sep).rsplit(sep)[-1] for x in items]
1288+
if current_item:
1289+
current_item = current_item.rstrip(sep).rsplit(sep)[-1]
1290+
1291+
if items[0].endswith(']'):
1292+
# dictionary key suggestions
1293+
items = [x.rstrip(']') for x in items]
12871294
if current_item:
1288-
current_item = current_item.rstrip(sep).rsplit(sep)[-1]
1295+
current_item = current_item.rstrip(']')
12891296

12901297
if topline:
12911298
height_offset = self.mkargspec(topline, down) + 1

0 commit comments

Comments
 (0)