Commit Graph

45 Commits

Author SHA1 Message Date
Sebastian Lohff b44a1f3543 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-02-16 17:55:01 +01:00
Sebastian Lohff 26412d400f Fix off-by-one in initial pos for menus with no header
Menus without a header had their initial position set to the second
element by default. This was due to most menus having a header and us
calling next_item() unconditionally. Now we first go to the first
focusable item and then call next_item() as many times as needed to get
to the specified initial_pos.
2023-02-16 10:53:02 +01:00
Sebastian Lohff 33aa41ac6e Return with "no success" when no options are given
If the user gave us no options then we used to just raise a ValueError
(due to initial_pos being out of range). In most - if not all - cases
it would be more favorable to act the same way as if the selection has
been aborted, so that's what we're doing now.
2023-02-16 10:52:14 +01:00
Sebastian Lohff 1a309d28c0 Release v0.2.0 2020-09-15 23:20:57 +02:00
Sebastian Lohff 775c50ed6f Add support for cursorless menus
When a highlighter is used instead of a cursor it looks much better when
all the options have the same length. With right_pad_options all options
are right-padded with spaces so they have the same length. Also, an
example for a cursorless menu is added.
2020-09-06 21:08:06 +02:00
Sebastian Lohff 7a09d45ab8 Allow styling special CliMultiMenu states
Now a selected and a selected and highlighted option can be styled.
2020-08-28 01:58:39 +02:00
Sebastian Lohff 19ad4f3e8b Allow per-item styling for text and options
When adding text or an option a style can now be passed along. An option
allows an additional highlighted_style to be passed.
2020-08-28 00:46:32 +02:00
Sebastian Lohff 030492b353 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.
2020-08-28 00:43:03 +02:00
Sebastian Lohff 22307bc4ae Always use text as item if no item was specified
When an option is passed without an item attached we now always use the
label as item. This was the behaviour for __init__() and is now also the
behaviour of add_option().
2020-08-28 00:26:32 +02:00
Sebastian Lohff 85c3c5c947 Make option prefix/suffix configurable
This can be used to add some text surrounding options or to remove the
space between cursor and option item.
2020-08-28 00:18:53 +02:00
Sebastian Lohff 68e6ecbe4f Make CliMenuHeader and CliMenuOption private
These classes don't need to be used by the user, only via the API, so we
can mark them private.
2020-08-26 23:46:35 +02:00
Sebastian Lohff 24dab5f69b Specify minimum selected item count for CliMutliMenu
min_selection_count=n can be specify to indicate that at least n
items need to be selected before the selection is accepted.
Feature inspired by python pick.
2020-08-21 00:09:12 +02:00
Sebastian Lohff 56b76706f6 Group selection icons in CliMultiMenu API
The select/unselect icons of a CliMultiMenu will in nearly all cases be
changed together, therefore it makes sense to let the API be less
verbose for this case.

This is an API breaking change for CliMultiMenu
2020-08-21 00:09:12 +02:00
Sebastian Lohff 12552d8e5b Use right arrow to select/deselect in CliMultiMenu
For a menu where we only select one option right arrow is an okay-choice
for accept, but with multiple option selection toggling feels more
natural.
2020-08-20 01:53:48 +02:00
Sebastian Lohff d01024d1be Add initial_pos to choose initially selected item 2020-08-20 01:39:35 +02:00
Sebastian Lohff 3e3ea53f5e Remove dead code 2020-08-20 01:28:05 +02:00
Sebastian Lohff c363c187bd Remove unused methods and unused arguments 2020-08-20 00:15:41 +02:00
Sebastian Lohff 94bb03dc07 Don't ignore cursor/style/icon if it is not None
To allow the user to set '' as a cursor we need to distinguish between
'' and None, same for select icons and styles.
2020-08-20 00:14:08 +02:00
Sebastian Lohff 4ba22a3a33 Make setup.cfg release ready, move to GitHub 2020-08-16 19:58:55 +02:00
Sebastian Lohff 34a3279e2f Improve README.md a tiny bit 2020-08-16 15:13:22 +02:00
Sebastian Lohff f20b5eac89 Add more examples 2020-08-16 14:24:47 +02:00
Sebastian Lohff 9b833db364 Check type of options passed to __init__ 2020-08-05 03:09:24 +02:00
Sebastian Lohff c74e3d68d6 Implement multiple selections with CliMultiMenu
CliMultiMenu works much in the same way as CliMenu but it allows for
selecting multiple items.
2020-08-05 02:49:05 +02:00
Sebastian Lohff 46a863b3cf Remove broken space keyboard binding for accept
Originally space was thought out to also accept the selection, but only
a broken binding was added. As we want to use space for selections in
the future we now remove it entirely.
2020-08-05 02:34:36 +02:00
Sebastian Lohff a28c76e001 Allow a default theme and cursor to be set 2020-08-05 02:32:33 +02:00
Sebastian Lohff 45d3395642 Rename add_header() to add_text()
add_header() does not necessarily add a header, it might be just text.
2020-07-22 02:08:53 +02:00
Sebastian Lohff a17f7693e9 Renamed CLI_* cursors to ASCII_* cursors 2020-07-22 02:07:45 +02:00
Sebastian Lohff 648d5c956e Use option text as title if no value is given
If the user only supplys a text for the option we used to return None as
item value. Now we return the text, so the user can easily get the value
back if they want to process it further and not only work with the given
option index (or supply the item twice).
2020-03-11 18:19:19 +01:00
Sebastian Lohff 8c6ee790bf Fix get_options() and num_options to work on options
get_options() and num_options used to work on all menu items, including
blank spaces and headers. Now these work only on options, as they were
originally intended
2020-03-11 18:18:26 +01:00
Sebastian Lohff 9fe596bc01 Add option to return instantly on single item in cli_select_item()
cli_select_item() allows to quickly launch a menu from code, but if only
a single item is given a selection is not necessary in most cases.
Therefore we now instantly return the given value in these cases. This
can be turned off by setting return_single=False
2020-03-11 17:55:16 +01:00
Sebastian Lohff d926606976 Add shortcut function to quickly get a selection result
cli_select_item() will instanciate a CliMenu and return a selection. If
the selection is aborted an exception of the given class will be thrown.
2020-01-23 09:59:55 +01:00
Sebastian Lohff 3d1d2d5acd Add theme example 2019-08-15 15:13:18 +02:00
Sebastian Lohff 58d6170a5c Add bold highlight style to defaults 2019-08-15 15:10:21 +02:00
Sebastian Lohff 206dcc46df Correct typo in var name 2019-08-15 15:10:07 +02:00
Sebastian Lohff 58455be58a Add methods to get all available menu options 2019-07-18 13:32:23 +02:00
Sebastian Lohff f0e5b7bb58 Implement searching for menu items
This uses prompt-toolkit's builtin search functionality to search
through the buffer representing the menu, allowing the user
to navigate faster through the entries
2019-04-22 14:35:38 +02:00
Sebastian Lohff ec07ebe536 Sort imports 2019-02-25 01:02:38 +01:00
Sebastian Lohff 6a128e13a6 Header indentation and tuple options for constructor 2019-02-13 10:18:26 +01:00
Sebastian Lohff 2f2049bfef Add k/j as up/down keys 2019-02-04 11:36:07 +01:00
Sebastian Lohff 0517b4d996 Return no selection if the user aborted selection
Also expose success state
2019-02-01 18:58:09 +01:00
Sebastian Lohff ad3fd751cc Move cursor along with selection for scrolling 2019-02-01 18:46:09 +01:00
Sebastian Lohff e0177d0e10 Fix inline header indentation 2019-02-01 18:17:57 +01:00
Sebastian Lohff b18372e3b8 Allow passing an item to each option 2019-02-01 18:17:57 +01:00
Sebastian Lohff 6655fd097a Add two simple examples 2019-02-01 00:03:42 +01:00
Sebastian Lohff bd31b70e44 Initial commit 2019-01-31 23:58:29 +01:00