Skip to content

Commit

Permalink
auto-select the single action if get_selection_actions returns a non-…
Browse files Browse the repository at this point in the history
…iterable
  • Loading branch information
koreno committed Mar 20, 2016
1 parent 067054c commit 79f3dea
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions termenu/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ class BackSignal(_MenuSignal): pass
class ReturnSignal(_MenuSignal): pass
class TimeoutSignal(_MenuSignal): pass

# yield this to add a separator
SEPARATOR = dict(text="BLACK<<%s>>" % ("-"*80), result=True, selectable=False)

_all_titles = []
_all_menus = []

Expand Down Expand Up @@ -492,12 +495,18 @@ def on_selected(self, selected):

actions = self.get_selection_actions(selected)

if actions is None:
ret = self.action(selected)
else:
if isinstance(actions, (list, tuple)):
to_submenu = lambda action: (_get_option_name(action), functools.partial(action, selected))
actions = [action if isinstance(action, collections.Callable) else getattr(self, action) for action in actions]
ret = self.show(title=self.get_selection_title(selected), options=list(map(to_submenu, actions)))
else:
if actions is None:
action = self.action
elif isinstance(actions, str):
action = getattr(self, actions)
else:
action = actions
ret = action(selected)

if ret is not None:
self.result(ret)
Expand Down

0 comments on commit 79f3dea

Please sign in to comment.