Compare commits
2 Commits
6655fd097a
...
e0177d0e10
Author | SHA1 | Date |
---|---|---|
Sebastian Lohff | e0177d0e10 | |
Sebastian Lohff | b18372e3b8 |
|
@ -19,9 +19,10 @@ class CliMenuHeader:
|
||||||
|
|
||||||
class CliMenuOption:
|
class CliMenuOption:
|
||||||
"""Hold a menu option"""
|
"""Hold a menu option"""
|
||||||
def __init__(self, text, num):
|
def __init__(self, text, num, item=None):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.num = num
|
self.num = num
|
||||||
|
self.item = item
|
||||||
self.focusable = True
|
self.focusable = True
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,19 +97,27 @@ class CliMenu:
|
||||||
for option in options:
|
for option in options:
|
||||||
self.add_option(option)
|
self.add_option(option)
|
||||||
|
|
||||||
def add_header(self, title, indent=False):
|
def add_header(self, title, indent=True):
|
||||||
for text in title.split('\n'):
|
for text in title.split('\n'):
|
||||||
self._items.append(CliMenuHeader(text))
|
self._items.append(CliMenuHeader(text, indent=indent))
|
||||||
|
|
||||||
def add_option(self, text):
|
def add_option(self, text, item=None):
|
||||||
self._items.append(CliMenuOption(text, self._item_num))
|
self._items.append(CliMenuOption(text, self._item_num, item=item))
|
||||||
self._item_num += 1
|
self._item_num += 1
|
||||||
|
|
||||||
def get_selection(self):
|
def get_selection(self):
|
||||||
if not self._ran:
|
if not self._ran:
|
||||||
self._run()
|
self._run()
|
||||||
|
|
||||||
return self._items[self._pos].num
|
item = self._items[self._pos]
|
||||||
|
|
||||||
|
return (item.num, item.item)
|
||||||
|
|
||||||
|
def get_selection_num(self):
|
||||||
|
return self.get_selection()[0]
|
||||||
|
|
||||||
|
def get_selection_item(self):
|
||||||
|
return self.get_selection()[1]
|
||||||
|
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
return '{} '.format(self._cursor)
|
return '{} '.format(self._cursor)
|
||||||
|
@ -137,7 +146,7 @@ class CliMenu:
|
||||||
style = s.option_style
|
style = s.option_style
|
||||||
else:
|
else:
|
||||||
if item.indent:
|
if item.indent:
|
||||||
indent += ' ' * self._header_indent
|
indent += ' ' * (self._header_indent + len(self._cursor) + 1)
|
||||||
style = s.header_style
|
style = s.header_style
|
||||||
|
|
||||||
return Transformation([('', indent), (style, prefix + text)])
|
return Transformation([('', indent), (style, prefix + text)])
|
||||||
|
|
Loading…
Reference in New Issue