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 15, 2016
1 parent 067054c commit 8886a10
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions termenu/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,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 8886a10

Please sign in to comment.