Improved menu

This commit is contained in:
Sven Heidemann 2021-11-23 11:48:33 +01:00
parent 5ddc2dc72d
commit 39cdd989f0
2 changed files with 39 additions and 17 deletions

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
source ../venv/bin/activate
export PYTHONPATH=./:$PYTHONPATH export PYTHONPATH=./:$PYTHONPATH
python3.9 multi_install_cli/main.py python3.9 multi_install_cli/main.py

View File

@ -1,4 +1,7 @@
from typing import Optional
from cpl_core.console import Console from cpl_core.console import Console
from cpl_query.extension import List
from multi_install.abc.menu_service_abc import MenuServiceABC from multi_install.abc.menu_service_abc import MenuServiceABC
from multi_install.config.os_settings import OSSettings from multi_install.config.os_settings import OSSettings
@ -8,38 +11,56 @@ class MenuService(MenuServiceABC):
def __init__(self, os_settings: OSSettings): def __init__(self, os_settings: OSSettings):
self._os_settings = os_settings self._os_settings = os_settings
self._is_running = True self._os: Optional[str] = None
def run(self): def run(self):
while self._is_running: is_end = False
os = self.select_os() while not is_end:
if os == 'Exit': self.select_os()
self._is_running = False
break
main_menu = self.main_menu() main_menu = self.main_menu()
if main_menu == 'Exit': if main_menu == 'Exit':
self._is_running = False is_end = True
elif main_menu == 'Back':
break break
def select_os(self) -> str: def select_os(self):
options = self._os_settings.operating_systems Console.clear()
options = List(str, self._os_settings.operating_systems.copy())
options.append('Exit') options.append('Exit')
return Console.select('>', 'Select OS:', options) Console.write_line('Select option:')
options.for_each(lambda o: Console.write_line(f'[{options.index(o)}] {o}'))
os = int(Console.read('\n:'))
if os == options.index('Exit'):
exit()
self._os = os
def main_menu(self) -> str: def main_menu(self) -> str:
options = [ Console.clear()
options = List(str, [
'Install collection', 'Install collection',
'Uninstall collection',
'Add collection', 'Add collection',
'Remove collection', 'Remove collection',
'Install application', 'Install application',
'Uninstall application',
'Add application', 'Add application',
'Remove application', 'Remove application',
'Add application' 'Add application',
]
options.append('Exit') 'Back',
return Console.select('>', 'Select option:', options) 'Exit'
])
Console.write_line('Select option:')
options.for_each(lambda o: Console.write_line(f'[{options.index(o)}] {o}'))
selected = int(Console.read('\n:'))
if selected == options.index('Exit'):
exit()
return selected
def select_collection(self) -> str: def select_collection(self) -> str:
options = [] options = []