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.
This commit is contained in:
Sebastian Lohff 2020-08-27 02:03:42 +02:00
parent 9ef6532c1f
commit dc3b03c653
2 changed files with 10 additions and 10 deletions

View File

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

View File

@ -23,7 +23,7 @@ print()
# --- custom themes --- # --- 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"] q = ["Foo", "Bar", "Baz"]
m = CliMenu(q, "Choose in style:\n", style=style) m = CliMenu(q, "Choose in style:\n", style=style)
print("You selected", m.get_selection()) print("You selected", m.get_selection())