Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu.py
diff options
context:
space:
mode:
authorDaniel <blackrabbit256@gmail.com>2022-01-07 21:48:23 +1100
committerGitHub <noreply@github.com>2022-01-07 10:48:23 +0000
commit1234261a7a0d3ffd20f0d4ebea0f54a30c493d45 (patch)
treea409365838e1312786a88028e2d42a3ebf087fc1 /archinstall/lib/menu.py
parent2190321eb43e4b0667bb41a0dd19f8df3c57a291 (diff)
Global menu (#806)
* Global menu * Fix flake8 * Refactor code * Add documentation * Fix flake8 * Add support for user flow mentioned in #799 * Move import * Fix flake8 (again) Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com> Co-authored-by: Anton Hvornum <anton.feeds@gmail.com>
Diffstat (limited to 'archinstall/lib/menu.py')
-rw-r--r--archinstall/lib/menu.py91
1 files changed, 0 insertions, 91 deletions
diff --git a/archinstall/lib/menu.py b/archinstall/lib/menu.py
deleted file mode 100644
index 6f1c2237..00000000
--- a/archinstall/lib/menu.py
+++ /dev/null
@@ -1,91 +0,0 @@
-from .simple_menu import TerminalMenu
-
-
-class Menu(TerminalMenu):
- def __init__(self, title, options, skip=True, multi=False, default_option=None, sort=True):
- """
- Creates a new menu
-
- :param title: Text that will be displayed above the menu
- :type title: str
-
- :param options: Options to be displayed in the menu to chose from;
- if dict is specified then the keys of such will be used as options
- :type options: list, dict
-
- :param skip: Indicate if the selection is not mandatory and can be skipped
- :type skip: bool
-
- :param multi: Indicate if multiple options can be selected
- :type multi: bool
-
- :param default_option: The default option to be used in case the selection processes is skipped
- :type default_option: str
-
- :param sort: Indicate if the options should be sorted alphabetically before displaying
- :type sort: bool
- """
-
- if isinstance(options, dict):
- options = list(options)
-
- if sort:
- options = sorted(options)
-
- self.menu_options = options
- self.skip = skip
- self.default_option = default_option
- self.multi = multi
-
- menu_title = f'\n{title}\n\n'
-
- if skip:
- menu_title += "Use ESC to skip\n\n"
-
- if default_option:
- # if a default value was specified we move that one
- # to the top of the list and mark it as default as well
- default = f'{default_option} (default)'
- self.menu_options = [default] + [o for o in self.menu_options if default_option != o]
-
- cursor = "> "
- main_menu_cursor_style = ("fg_cyan", "bold")
- main_menu_style = ("bg_blue", "fg_gray")
-
- super().__init__(
- menu_entries=self.menu_options,
- title=menu_title,
- menu_cursor=cursor,
- menu_cursor_style=main_menu_cursor_style,
- menu_highlight_style=main_menu_style,
- cycle_cursor=True,
- clear_screen=True,
- multi_select=multi,
- show_search_hint=True
- )
-
- def _show(self):
- idx = self.show()
- if idx is not None:
- if isinstance(idx, (list, tuple)):
- return [self.default_option if ' (default)' in self.menu_options[i] else self.menu_options[i] for i in idx]
- else:
- selected = self.menu_options[idx]
- if ' (default)' in selected and self.default_option:
- return self.default_option
- return selected
- else:
- if self.default_option:
- if self.multi:
- return [self.default_option]
- else:
- return self.default_option
- return None
-
- def run(self):
- ret = self._show()
-
- if ret is None and not self.skip:
- return self.run()
-
- return ret