From 7dd423ca506ae0ae46be015d6e1564d2b24ae36a Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 4 Mar 2018 13:43:33 +0100 Subject: Show the full keybindings in the key hints --- ranger/gui/widgets/view_base.py | 53 +++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index cb205d92..b005f1d5 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -112,16 +112,49 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan self.color_reset() self.need_clear = True hints = [] - for key, value in self.fm.ui.keybuffer.pointer.items(): - key = key_to_string(key) - if isinstance(value, dict): - text = '...' - else: - text = value - if text.startswith('hint') or text.startswith('chain hint'): - continue - hints.append((key, text)) - hints.sort(key=lambda t: t[1]) + + def populate_hints(keymap, prefix=""): + for key, value in keymap.items(): + key = prefix + key_to_string(key) + if isinstance(value, dict): + populate_hints(value, key) + else: + text = value + if text.startswith('hint') or text.startswith('chain hint'): + continue + hints.append((key, text)) + populate_hints(self.fm.ui.keybuffer.pointer) + + def sort_hints(hints): + """Sort the hints by the action string but first group them by the + first key. + + """ + from itertools import groupby + + # groupby needs the list to be sorted + hints.sort(key=lambda t: t[0]) + + def group_hints(hints): + def first_key(hint): + return hint[0][0] + + def action_string(hint): + return hint[1] + + return (list(sorted(group, key=action_string)) + for _, group + in groupby( + hints, + key=first_key)) + hints = sorted( + group_hints(hints), + key=lambda g: g[0][1]) # sort by the first action in group + + def flatten(nested_list): + return [item for inner_list in nested_list for item in inner_list] + return flatten(hints) + hints = sort_hints(hints) hei = min(self.hei - 1, len(hints)) ystart = self.hei - hei -- cgit 1.4.1-2-gfad0