diff options
author | John Estabrook <jestabro@vyos.io> | 2023-10-31 12:53:52 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-11-16 12:19:15 -0600 |
commit | 9ffa3e82d951756696367578dd5e82ef0f690065 (patch) | |
tree | 4c5b2b2fe6881f407e5076647f3d1db99b5cf458 /python/vyos/utils/io.py | |
parent | 3d15cfd484e8c2732d9f10e4065f2282f1f5d334 (diff) | |
download | vyos-1x-9ffa3e82d951756696367578dd5e82ef0f690065.tar.gz vyos-1x-9ffa3e82d951756696367578dd5e82ef0f690065.zip |
image: T4516: restore select entry to set/delete image
Diffstat (limited to 'python/vyos/utils/io.py')
-rw-r--r-- | python/vyos/utils/io.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py index 8790cbaac..e34a1ba32 100644 --- a/python/vyos/utils/io.py +++ b/python/vyos/utils/io.py @@ -72,3 +72,22 @@ def is_dumb_terminal(): """Check if the current TTY is dumb, so that we can disable advanced terminal features.""" import os return os.getenv('TERM') in ['vt100', 'dumb'] + +def select_entry(l: list, list_msg: str = '', prompt_msg: str = '') -> str: + """Select an entry from a list + + Args: + l (list): a list of entries + list_msg (str): a message to print before listing the entries + prompt_msg (str): a message to print as prompt for selection + + Returns: + str: a selected entry + """ + en = list(enumerate(l, 1)) + print(list_msg) + for i, e in en: + print(f'\t{i}: {e}') + select = ask_input(prompt_msg, numeric_only=True, + valid_responses=range(1, len(l)+1)) + return next(filter(lambda x: x[0] == select, en))[1] |