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
# -*- coding: utf-8 -*-
source ../venv/bin/activate
export PYTHONPATH=./:$PYTHONPATH
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_query.extension import List
from multi_install.abc.menu_service_abc import MenuServiceABC
from multi_install.config.os_settings import OSSettings
@ -8,38 +11,56 @@ class MenuService(MenuServiceABC):
def __init__(self, os_settings: OSSettings):
self._os_settings = os_settings
self._is_running = True
self._os: Optional[str] = None
def run(self):
while self._is_running:
os = self.select_os()
if os == 'Exit':
self._is_running = False
break
is_end = False
while not is_end:
self.select_os()
main_menu = self.main_menu()
if main_menu == 'Exit':
self._is_running = False
is_end = True
elif main_menu == 'Back':
break
def select_os(self) -> str:
options = self._os_settings.operating_systems
def select_os(self):
Console.clear()
options = List(str, self._os_settings.operating_systems.copy())
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:
options = [
Console.clear()
options = List(str, [
'Install collection',
'Uninstall collection',
'Add collection',
'Remove collection',
'Install application',
'Uninstall application',
'Add application',
'Remove application',
'Add application'
]
options.append('Exit')
return Console.select('>', 'Select option:', options)
'Add application',
'Back',
'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:
options = []