Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple menu for better UX #660

Merged
merged 25 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
deff005
Add simple menu for better UX
svartkanin Oct 11, 2021
0e7969c
PR feedback
svartkanin Oct 27, 2021
697dce9
Merge remote-tracking branch 'origin/master' into add-menu
svartkanin Nov 7, 2021
bdcf33c
Add remove external dependency
svartkanin Nov 8, 2021
36ed68b
Fix harddisk return value on skip
svartkanin Nov 8, 2021
5e555f7
Table output for partitioning process
svartkanin Nov 8, 2021
bb915a3
Switch partitioning to simple menu
svartkanin Nov 9, 2021
956b614
fixup! Switch partitioning to simple menu
svartkanin Nov 10, 2021
e3bf635
Uncomment
svartkanin Nov 10, 2021
4028936
Update
svartkanin Nov 10, 2021
cbfcf33
Simplify code
svartkanin Nov 10, 2021
ac173c0
Calling fs_types() to get the response
Torxed Nov 11, 2021
c57bf22
Ignoring complexity and binary operator issues
Torxed Nov 11, 2021
07a520e
Added license text to the MIT licensed file
Torxed Nov 11, 2021
67ae610
Added in versioning information
Torxed Nov 11, 2021
638f970
Linting issue fix
Torxed Nov 11, 2021
4e9330a
Merged latest master
Torxed Nov 11, 2021
54a65b6
Pulled fix for multi select search
svartkanin Nov 20, 2021
1f8f487
Merged master
Nov 25, 2021
73a5e0b
Fixed some imports and removed the last generic_select() from user_in…
Nov 25, 2021
399cfd7
Incorrect usage of archinstall. inside the library.
Nov 25, 2021
a5eee0c
Update color scheme to match Arch style better
dylanmtaylor Nov 26, 2021
9b2252d
Use cyan as default cursor color
dylanmtaylor Nov 26, 2021
c7194da
Leave simple menu the same
dylanmtaylor Nov 29, 2021
fc2e72a
Merge pull request #1 from dylanmtaylor/patch-1
svartkanin Nov 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ max-complexity = 40
max-line-length = 236
show-source = True
statistics = True
per-file-ignores = __init__.py:F401,F403,F405
per-file-ignores = __init__.py:F401,F403,F405 simple_menu.py:C901,W503
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ SAFETY_LOCK
/guided.py
/install.log
venv
.venv
.idea/**
**/install.log
**/install.log
2 changes: 1 addition & 1 deletion archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .lib.storage import *
from .lib.systemd import *
from .lib.user_interaction import *
from .lib.menu import Menu

parser = ArgumentParser()

Expand Down Expand Up @@ -88,7 +89,6 @@ def initialize_arguments():

# TODO: Learn the dark arts of argparse... (I summon thee dark spawn of cPython)


def run_as_a_module():
"""
Since we're running this as a 'python -m archinstall' module OR
Expand Down
18 changes: 11 additions & 7 deletions archinstall/lib/disk/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def valid_parted_position(pos :str):

return False

def valid_fs_type(fstype :str) -> bool:

def fs_types():
# https://www.gnu.org/software/parted/manual/html_node/mkpart.html
# Above link doesn't agree with `man parted` /mkpart documentation:
"""
Expand All @@ -27,16 +28,19 @@ def valid_fs_type(fstype :str) -> bool:
"linux-swap", "ntfs", "reis‐
erfs", "udf", or "xfs".
"""

return fstype.lower() in [
return [
"btrfs",
"ext2",
"ext3", "ext4", # `man parted` allows these
"ext3", "ext4", # `man parted` allows these
"fat16", "fat32",
"hfs", "hfs+", # "hfsx", not included in `man parted`
"hfs", "hfs+", # "hfsx", not included in `man parted`
"linux-swap",
"ntfs",
"reiserfs",
"udf", # "ufs", not included in `man parted`
"xfs", # `man parted` allows this
"udf", # "ufs", not included in `man parted`
"xfs", # `man parted` allows this
]


def valid_fs_type(fstype :str) -> bool:
return fstype.lower() in fs_types()
5 changes: 5 additions & 0 deletions archinstall/lib/locale_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ def set_keyboard_language(locale):
return True

return False


def list_timezones():
for line in SysCommand("timedatectl --no-pager list-timezones", environment_vars={'SYSTEMD_COLORS': '0'}):
yield line.decode('UTF-8').strip()
91 changes: 91 additions & 0 deletions archinstall/lib/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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_red", "bold")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of this color scheme. Maybe we could go with something close to the Arch blue to match?

main_menu_style = ("bg_red", "fg_yellow")

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.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
Loading