Commit Graph

31 Commits

Author SHA1 Message Date
Sebastian Lohff 9ef6532c1f Make option prefix/suffix configurable
This can be used to add some test surrounding options or to remove the
space between cursor and option item.
2020-08-27 01:57:02 +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 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 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 bd31b70e44 Initial commit 2019-01-31 23:58:29 +01:00