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 From 6f8fa8b5ef21792a69066500375b3643c50decfb Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 4 Mar 2018 14:13:55 +0100 Subject: Add the 'hint_collapse_threshold' that controls when the submaps are collapsed --- doc/ranger.pod | 5 +++++ ranger/config/rc.conf | 4 ++++ ranger/container/settings.py | 1 + ranger/gui/widgets/view_base.py | 21 ++++++++++++++++----- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/ranger.pod b/doc/ranger.pod index 523d8d9d..71a9342d 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -791,6 +791,11 @@ this pattern will hide all files that start with a dot or end with a tilde. set hidden_filter ^\.|~$ +=item hint_collapse_threshold [int] + +The key hint lists up to this size have their sublists expanded. +Otherwise the submaps are replaced with "...". + =item idle_delay [integer] The delay that ranger idly waits for user input, in milliseconds, with a diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 676090fb..fe00c7c0 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -216,6 +216,10 @@ set cd_tab_fuzzy false # disable this feature. set preview_max_size 0 +# The key hint lists up to this size have their sublists expanded. +# Otherwise the submaps are replaced with "...". +set hint_collapse_threshold 10 + # Add the highlighted file to the path in the titlebar set show_selection_in_titlebar true diff --git a/ranger/container/settings.py b/ranger/container/settings.py index d0b094d0..8b7364a2 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -45,6 +45,7 @@ ALLOWED_SETTINGS = { 'freeze_files': bool, 'global_inode_type_filter': str, 'hidden_filter': str, + 'hint_collapse_threshold' : int, 'hostname_in_titlebar': bool, 'idle_delay': int, 'iterm2_font_width': int, diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index b005f1d5..0878ab0f 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -132,7 +132,7 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan """ from itertools import groupby - # groupby needs the list to be sorted + # groupby needs the list to be sorted. hints.sort(key=lambda t: t[0]) def group_hints(hints): @@ -147,13 +147,24 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan in groupby( hints, key=first_key)) - hints = sorted( - group_hints(hints), - key=lambda g: g[0][1]) # sort by the first action in group + + grouped_hints = group_hints(hints) + + # If there are too many hints, collapse the sublists. + if len(hints) > self.fm.settings.hint_collapse_threshold: + def first_key_in_group(group): + return group[0][0][0] + grouped_hints = [[(first_key_in_group(hint_group), "...")] + if len(hint_group) > 1 + else hint_group + for hint_group in grouped_hints] + + # Sort by the first action in group. + grouped_hints = sorted(grouped_hints, key=lambda g: g[0][1]) def flatten(nested_list): return [item for inner_list in nested_list for item in inner_list] - return flatten(hints) + return flatten(grouped_hints) hints = sort_hints(hints) hei = min(self.hei - 1, len(hints)) -- cgit 1.4.1-2-gfad0 From 9b98c70088a31cfce75f5e560bcac3a351532b24 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 4 Mar 2018 14:20:03 +0100 Subject: Fix the coding style --- ranger/container/settings.py | 2 +- ranger/gui/widgets/view_base.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 8b7364a2..9f54f24d 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -45,7 +45,7 @@ ALLOWED_SETTINGS = { 'freeze_files': bool, 'global_inode_type_filter': str, 'hidden_filter': str, - 'hint_collapse_threshold' : int, + 'hint_collapse_threshold': int, 'hostname_in_titlebar': bool, 'idle_delay': int, 'iterm2_font_width': int, diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index 0878ab0f..c87bdede 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -154,10 +154,12 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan if len(hints) > self.fm.settings.hint_collapse_threshold: def first_key_in_group(group): return group[0][0][0] - grouped_hints = [[(first_key_in_group(hint_group), "...")] - if len(hint_group) > 1 - else hint_group - for hint_group in grouped_hints] + grouped_hints = [ + [(first_key_in_group(hint_group), "...")] + if len(hint_group) > 1 + else hint_group + for hint_group in grouped_hints + ] # Sort by the first action in group. grouped_hints = sorted(grouped_hints, key=lambda g: g[0][1]) -- cgit 1.4.1-2-gfad0 From 727fd3aa19b904e6359d76792735fa155015a0ec Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 4 Mar 2018 14:24:32 +0100 Subject: Update the manpage --- doc/ranger.1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index fca30604..ded6a5d6 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.9.1" "02/22/2018" "ranger manual" +.TH RANGER 1 "ranger-1.9.1" "03/04/2018" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -800,6 +800,10 @@ this pattern will hide all files that start with a dot or end with a tilde. .Vb 1 \& set hidden_filter ^\e.|~$ .Ve +.IP "hint_collapse_threshold [int]" 4 +.IX Item "hint_collapse_threshold [int]" +The key hint lists up to this size have their sublists expanded. +Otherwise the submaps are replaced with \*(L"...\*(R". .IP "idle_delay [integer]" 4 .IX Item "idle_delay [integer]" The delay that ranger idly waits for user input, in milliseconds, with a -- cgit 1.4.1-2-gfad0 From 72ea7926b30e0842ac213aab23d9f94df1cdbb50 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 4 Mar 2018 15:07:23 +0100 Subject: Cleanup lists and generators --- ranger/gui/widgets/view_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index c87bdede..80061004 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -142,7 +142,7 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan def action_string(hint): return hint[1] - return (list(sorted(group, key=action_string)) + return (sorted(group, key=action_string) for _, group in groupby( hints, @@ -154,12 +154,12 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan if len(hints) > self.fm.settings.hint_collapse_threshold: def first_key_in_group(group): return group[0][0][0] - grouped_hints = [ + grouped_hints = ( [(first_key_in_group(hint_group), "...")] if len(hint_group) > 1 else hint_group for hint_group in grouped_hints - ] + ) # Sort by the first action in group. grouped_hints = sorted(grouped_hints, key=lambda g: g[0][1]) -- cgit 1.4.1-2-gfad0