Return no selection if the user aborted selection

Also expose success state
This commit is contained in:
Sebastian Lohff 2019-02-01 18:58:09 +01:00
parent ad3fd751cc
commit 0517b4d996
1 changed files with 10 additions and 3 deletions

View File

@ -105,13 +105,20 @@ class CliMenu:
self._items.append(CliMenuOption(text, self._item_num, item=item)) self._items.append(CliMenuOption(text, self._item_num, item=item))
self._item_num += 1 self._item_num += 1
def get_selection(self): @property
def success(self):
if not self._ran: if not self._ran:
self._run() self._run()
item = self._items[self._pos] return self._success
return (item.num, item.item) def get_selection(self):
if self.success:
item = self._items[self._pos]
return (item.num, item.item)
else:
return (None, None)
def get_selection_num(self): def get_selection_num(self):
return self.get_selection()[0] return self.get_selection()[0]