Compare commits

..

4 Commits

Author SHA1 Message Date
Sebastian Lohff 54ecbe2447 Release v0.3.0
See the individual commits for details.

Breaking change: add_option() got an extra argument before the style
argument.
2023-03-20 16:25:20 +01:00
Sebastian Lohff dab559e5d7 Bump minimum python version to 3.7
Python lower than 3.7 is EOL, we're supporting up to what's currently
released, namely 3.11.
2023-03-20 16:23:02 +01:00
Sebastian Lohff be411066dc Allow disabled options to be created
add_option() now has a "disabled" parameter, which will add the given
option as a simple indented text. This is very similar as calling
add_text(). The advantage of having this as a parameter to add_option()
is that disabled options can now be created from the shorthand function
cli_select_item() by passing each option as a tuple or dict, which has
disabled=True set.

This is a breaking change, as the parameter order of add_option()
changes.
2023-03-20 16:14:39 +01:00
Sebastian Lohff 43ae293359 Add ctrl+n / ctrl+p as shortcuts for down and up
ctrl+n is used for "next item" aka down, ctrl+p as "previous item" aka
up.

Fixes #1
2023-03-17 16:25:26 +01:00
2 changed files with 21 additions and 12 deletions

View File

@ -132,11 +132,15 @@ class CliMenu:
for text in title.split('\n'):
self._items.append(_CliMenuHeader(text, indent=indent, style=style))
def add_option(self, text, item=_EmptyParameter, style=None, highlighted_style=None):
def add_option(self, text, item=_EmptyParameter, disabled=False, style=None, highlighted_style=None):
if disabled:
# this is basically a text option and we just throw the item away
self.add_text(title=text, style=style)
else:
if item == _EmptyParameter:
item = text
self._items.append(_CliMenuOption(text, self._item_num, item=item,
style=style, highlighted_style=highlighted_style))
opt = _CliMenuOption(text, self._item_num, item=item, style=style, highlighted_style=highlighted_style)
self._items.append(opt)
self._item_num += 1
@property
@ -293,11 +297,13 @@ class CliMenu:
@self._kb.add('down', filter=~is_searching)
@self._kb.add('j', filter=~is_searching)
@self._kb.add('c-n', filter=~is_searching)
def down(event):
self.next_item(1)
@self._kb.add('up', filter=~is_searching)
@self._kb.add('k', filter=~is_searching)
@self._kb.add('c-p', filter=~is_searching)
def up(event):
self.next_item(-1)
@ -369,9 +375,11 @@ class CliMultiMenu(CliMenu):
self._selection_icons = selection_icons if selection_icons is not None else self.default_selection_icons
super().__init__(*args, **kwargs)
def add_option(self, text, item=_EmptyParameter, selected=False,
def add_option(self, text, item=_EmptyParameter, selected=False, disabled=False,
style=None, highlighted_style=None, selected_style=None, selected_highlighted_style=None):
super().add_option(text, item, style, highlighted_style=highlighted_style)
super().add_option(text, item, disabled=disabled, style=style, highlighted_style=highlighted_style)
if disabled:
return
self._items[-1].selected_style = selected_style
self._items[-1].selected_highlighted_style = selected_highlighted_style
if selected:

View File

@ -1,6 +1,6 @@
[metadata]
name = clintermission
version = 0.2.0
version = 0.3.0
author = Sebastian Lohff
author-email = seba@someserver.de
license = Apache-2.0
@ -14,14 +14,15 @@ classifiers =
Development Status :: 3 - Alpha
Intended Audience :: Developers
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
License :: OSI Approved :: Apache Software License
[options]
python_requires = >= 3.5
python_requires = >= 3.7
packages = clintermission
setup_requires =
setuptools > 30.4.0