Downstream merged simple menu changes (#1356)

Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
Daniel Girtler 2022-08-01 18:28:41 +10:00 committed by GitHub
parent 3da03a192e
commit 1bd2210e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 36 deletions

View File

@ -56,8 +56,8 @@ class Menu(TerminalMenu):
preview_size=0.75,
preview_title='Info',
header :Union[List[str],str] = None,
explode_on_interrupt :bool = False,
explode_warning :str = '',
raise_error_on_interrupt :bool = False,
raise_error_warning_msg :str = '',
clear_screen: bool = True,
show_search_hint: bool = True,
cycle_cursor: bool = True,
@ -104,10 +104,10 @@ class Menu(TerminalMenu):
param header: one or more header lines for the menu
type param: string or list
param explode_on_interrupt: This will explicitly handle a ctrl+c instead and return that specific state
param raise_error_on_interrupt: This will explicitly handle a ctrl+c instead and return that specific state
type param: bool
param explode_warning: If explode_on_interrupt is True and this is non-empty, there will be a warning with a user confirmation displayed
param raise_error_warning_msg: If raise_error_on_interrupt is True and this is non-empty, there will be a warning with a user confirmation displayed
type param: str
:param kwargs : any SimpleTerminal parameter
@ -150,8 +150,8 @@ class Menu(TerminalMenu):
self._skip = skip
self._default_option = default_option
self._multi = multi
self._explode_on_interrupt = explode_on_interrupt
self._explode_warning = explode_warning
self._raise_error_on_interrupt = raise_error_on_interrupt
self._raise_error_warning_msg = raise_error_warning_msg
menu_title = f'\n{title}\n\n'
@ -164,7 +164,7 @@ class Menu(TerminalMenu):
if skip:
action_info += str(_("Use ESC to skip"))
if self._explode_on_interrupt:
if self._raise_error_on_interrupt:
if len(action_info) > 0:
action_info += '\n'
action_info += str(_('Use CTRL+C to reset current selection\n\n'))
@ -198,7 +198,7 @@ class Menu(TerminalMenu):
preview_command=preview_command,
preview_size=preview_size,
preview_title=preview_title,
explode_on_interrupt=self._explode_on_interrupt,
raise_error_on_interrupt=self._raise_error_on_interrupt,
multi_select_select_on_accept=False,
clear_screen=clear_screen,
show_search_hint=show_search_hint,
@ -236,8 +236,8 @@ class Menu(TerminalMenu):
ret = self._show()
if ret.type_ == MenuSelectionType.Ctrl_c:
if self._explode_on_interrupt and len(self._explode_warning) > 0:
response = Menu(self._explode_warning, Menu.yes_no(), skip=False).run()
if self._raise_error_on_interrupt and len(self._raise_error_warning_msg) > 0:
response = Menu(self._raise_error_warning_msg, Menu.yes_no(), skip=False).run()
if response.value == Menu.no():
return self.run()

View File

@ -65,7 +65,7 @@ __author__ = "Ingo Meyer"
__email__ = "i.meyer@fz-juelich.de"
__copyright__ = "Copyright © 2021 Forschungszentrum Jülich GmbH. All rights reserved."
__license__ = "MIT"
__version_info__ = (1, 4, 1)
__version_info__ = (1, 5, 0)
__version__ = ".".join(map(str, __version_info__))
@ -86,6 +86,7 @@ DEFAULT_MULTI_SELECT_SELECT_ON_ACCEPT = True
DEFAULT_PREVIEW_BORDER = True
DEFAULT_PREVIEW_SIZE = 0.25
DEFAULT_PREVIEW_TITLE = "preview"
DEFAULT_QUIT_KEYS = ("escape", "q")
DEFAULT_SEARCH_CASE_SENSITIVE = False
DEFAULT_SEARCH_HIGHLIGHT_STYLE = ("fg_black", "bg_yellow", "bold")
DEFAULT_SEARCH_KEY = "/"
@ -581,6 +582,8 @@ class TerminalMenu:
preview_command: Optional[Union[str, Callable[[str], str]]] = None,
preview_size: float = DEFAULT_PREVIEW_SIZE,
preview_title: str = DEFAULT_PREVIEW_TITLE,
quit_keys: Iterable[str] = DEFAULT_QUIT_KEYS,
raise_error_on_interrupt: bool = False,
search_case_sensitive: bool = DEFAULT_SEARCH_CASE_SENSITIVE,
search_highlight_style: Optional[Iterable[str]] = DEFAULT_SEARCH_HIGHLIGHT_STYLE,
search_key: Optional[str] = DEFAULT_SEARCH_KEY,
@ -596,8 +599,7 @@ class TerminalMenu:
status_bar: Optional[Union[str, Iterable[str], Callable[[str], str]]] = None,
status_bar_below_preview: bool = DEFAULT_STATUS_BAR_BELOW_PREVIEW,
status_bar_style: Optional[Iterable[str]] = DEFAULT_STATUS_BAR_STYLE,
title: Optional[Union[str, Iterable[str]]] = None,
explode_on_interrupt: bool = False
title: Optional[Union[str, Iterable[str]]] = None
):
def extract_shortcuts_menu_entries_and_preview_arguments(
entries: Iterable[str],
@ -619,7 +621,7 @@ class TerminalMenu:
else:
unit_separated_entry = escaped_separator_pattern.sub("|", separator_pattern.sub("\\1\x1F", entry))
match_obj = menu_entry_pattern.match(unit_separated_entry)
# this is none in case the entry was an empty string which
# this is none in case the entry was an emtpy string which
# will be interpreted as a separator
assert match_obj is not None
shortcut_key = match_obj.group(1)
@ -716,10 +718,11 @@ class TerminalMenu:
self._preview_command = preview_command
self._preview_size = preview_size
self._preview_title = preview_title
self._quit_keys = tuple(quit_keys)
self._raise_error_on_interrupt = raise_error_on_interrupt
self._search_case_sensitive = search_case_sensitive
self._search_highlight_style = tuple(search_highlight_style) if search_highlight_style is not None else ()
self._search_key = search_key
self._explode_on_interrupt = explode_on_interrupt
self._shortcut_brackets_highlight_style = (
tuple(shortcut_brackets_highlight_style) if shortcut_brackets_highlight_style is not None else ()
)
@ -787,6 +790,7 @@ class TerminalMenu:
# backspace can be queried from the terminal database but is unreliable, query the terminal directly instead
self._init_backspace_control_character()
self._add_missing_control_characters_for_keys(self._accept_keys)
self._add_missing_control_characters_for_keys(self._quit_keys)
self._init_terminal_codes()
@staticmethod
@ -1477,7 +1481,7 @@ class TerminalMenu:
"menu_down": set(("down", "ctrl-j", "j")),
"accept": set(self._accept_keys),
"multi_select": set(self._multi_select_keys),
"quit": set(("escape", "q")),
"quit": set(self._quit_keys),
"search_start": set((self._search_key,)),
"backspace": set(("backspace",)),
} # type: Dict[str, Set[Optional[str]]]
@ -1541,7 +1545,7 @@ class TerminalMenu:
# `search_start` key
self._search.search_text += next_key
except KeyboardInterrupt as e:
if self._explode_on_interrupt:
if self._raise_error_on_interrupt:
raise e
menu_was_interrupted = True
finally:
@ -1845,12 +1849,6 @@ def get_argumentparser() -> argparse.ArgumentParser:
),
)
parser.add_argument("-t", "--title", action="store", dest="title", help="menu title")
parser.add_argument(
"--explode-on-interrupt",
action="store_true",
dest="explode_on_interrupt",
help="Instead of quitting the menu, this will raise the KeyboardInterrupt Exception",
)
parser.add_argument(
"-V", "--version", action="store_true", dest="print_version", help="print the version number and exit"
)
@ -1981,7 +1979,6 @@ def main() -> None:
status_bar_below_preview=args.status_bar_below_preview,
status_bar_style=args.status_bar_style,
title=args.title,
explode_on_interrupt=args.explode_on_interrupt,
)
except (InvalidParameterCombinationError, InvalidStyleError, UnknownMenuEntryError) as e:
print(str(e), file=sys.stderr)

View File

@ -45,8 +45,8 @@ def select_disk_layout(preset: Optional[Dict[str, Any]], block_devices: list, ad
choice = Menu(
_('Select what you wish to do with the selected block devices'),
modes,
explode_on_interrupt=True,
explode_warning=warning
raise_error_on_interrupt=True,
raise_error_warning_msg=warning
).run()
match choice.type_:

View File

@ -109,7 +109,7 @@ def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
list(mirrors.keys()),
preset_values=preselected,
multi=True,
explode_on_interrupt=True
raise_error_on_interrupt=True
).run()
match selected_mirror.type_:
@ -159,8 +159,8 @@ def select_profile(preset) -> Optional[Profile]:
selection = Menu(
title=title,
p_options=list(options.keys()),
explode_on_interrupt=True,
explode_warning=warning
raise_error_on_interrupt=True,
raise_error_warning_msg=warning
).run()
match selection.type_:
@ -222,7 +222,7 @@ def select_additional_repositories(preset: List[str]) -> List[str]:
sort=False,
multi=True,
preset_values=preset,
explode_on_interrupt=True
raise_error_on_interrupt=True
).run()
match choice.type_:

View File

@ -154,8 +154,8 @@ def ask_to_configure_network(
list(network_options.values()),
cursor_index=cursor_idx,
sort=False,
explode_on_interrupt=True,
explode_warning=warning
raise_error_on_interrupt=True,
raise_error_warning_msg=warning
).run()
match choice.type_:

View File

@ -32,8 +32,8 @@ def select_kernel(preset: List[str] = None) -> List[str]:
sort=True,
multi=True,
preset_values=preset,
explode_on_interrupt=True,
explode_warning=warning
raise_error_on_interrupt=True,
raise_error_warning_msg=warning
).run()
match choice.type_:
@ -67,8 +67,8 @@ def select_harddrives(preset: List[str] = []) -> List[str]:
list(options.keys()),
preset_values=list(preset_disks.keys()),
multi=True,
explode_on_interrupt=True,
explode_warning=warning
raise_error_on_interrupt=True,
raise_error_warning_msg=warning
).run()
match selected_harddrive.type_: