Rename CliMenuTheme class parameters

The _style is redundant, as the whole theme is a collection of styles.
Headers are not really regarded as headers, more as text. Highlight
makes more sense as highlighted.

This is an API breaking change.
new-styles
Sebastian Lohff 4 years ago
parent 9ef6532c1f
commit dc3b03c653

@ -45,10 +45,10 @@ class CliMenuStyle:
Allows to select header, option and selected option color
"""
def __init__(self, option_style='', highlight_style='', header_style=''):
self.option_style = option_style
self.highlight_style = highlight_style
self.header_style = header_style
def __init__(self, option='', highlighted='', text=''):
self.option = option
self.highlighted = highlighted
self.text = text
class CliSelectionStyle:
@ -62,12 +62,12 @@ class CliSelectionStyle:
class CliMenuTheme:
BASIC = CliMenuStyle()
BASIC_BOLD = CliMenuStyle(header_style='bold', highlight_style='bold')
BASIC_BOLD = CliMenuStyle(text='bold', highlighted='bold')
RED = CliMenuStyle('#aa0000', '#ee0000', '#aa0000')
CYAN = CliMenuStyle('cyan', 'lightcyan', 'cyan')
BLUE = CliMenuStyle('ansiblue', 'ansired', 'ansiblue')
ANSI_CYAN = CliMenuStyle('ansicyan', 'ansibrightcyan', 'ansicyan')
BOLD_HIGHLIGHT = CliMenuStyle(header_style='bold', highlight_style='bold fg:black bg:white')
BOLD_HIGHLIGHT = CliMenuStyle(text='bold', highlighted='bold fg:black bg:white')
class CliMenu:
@ -173,14 +173,14 @@ class CliMenu:
if ti.lineno == self._pos:
prefix += '{}{}'.format(self._cursor, self._option_prefix)
style = s.highlight_style
style = s.highlighted
else:
prefix += ' ' * len(self._cursor) + self._option_prefix + ' ' * self._dedent_selection
style = s.option_style
style = s.option
else:
if item.indent:
indent += ' ' * (self._header_indent + len(self._cursor) + 1)
style = s.header_style
style = s.text
items = [(s if s else style, t) for s, t in ti.fragments]
prefix = self._transform_prefix(item, ti.lineno, prefix)

@ -23,7 +23,7 @@ print()
# --- custom themes ---
style = CliMenuStyle(option_style='blue', highlight_style='cyan', header_style='green')
style = CliMenuStyle(option='blue', highlighted='cyan', text='green')
q = ["Foo", "Bar", "Baz"]
m = CliMenu(q, "Choose in style:\n", style=style)
print("You selected", m.get_selection())

Loading…
Cancel
Save