mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 19:02:31 +00:00
feat(menu): search options and applications from the main menu
The main menu opens with a search that finds an option of ProxMenux, an application of the OCI catalog or a Helper-Script by its name or by related words, in that order, and by category after the names. Every result opens what its name says and nothing is run by the search itself: a script starts at its first screen, an application opens its page, an option of the post-install or a system utility opens its list with it marked, and an option that lives inside a menu is opened by that menu, which stays behind it. The menus take the option to open as an argument and behave as before without one. The Helper-Scripts catalog is kept on the host and refreshed once a day. The main menu, the lists of OCI manager and the Helper-Scripts menu share the same height.
This commit is contained in:
@@ -27,7 +27,7 @@ from .installer import (
|
||||
run_remote_install,
|
||||
run_remote_rclone_mount,
|
||||
)
|
||||
from .ui import APP_TITLE, DETAIL_WINDOW_WIDTH, UserCancelled, interactive_ui
|
||||
from .ui import APP_TITLE, DETAIL_WINDOW_WIDTH, UserCancelled, interactive_ui, menu_size
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
@@ -66,7 +66,7 @@ def is_tested(item: dict[str, Any]) -> bool:
|
||||
or bool((item.get("community_tested") or {}).get("by")))
|
||||
|
||||
|
||||
MENU_SIZE = (22, 75, 15)
|
||||
MENU_SIZE = menu_size()
|
||||
MULTI_LABEL = r"\Z4MULTI\Zn"
|
||||
TESTED_LABEL = r"\Z2✓\Zn"
|
||||
|
||||
@@ -620,6 +620,8 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
subparsers.add_parser("apply-icons", help="Resolve catalog icons against the jsdelivr icon sets")
|
||||
show_parser = subparsers.add_parser("show", help="Show the summary of a template")
|
||||
show_parser.add_argument("app")
|
||||
open_parser = subparsers.add_parser("open", help="Open the page of an application in the menu")
|
||||
open_parser.add_argument("app")
|
||||
install_parser = subparsers.add_parser("install", help="Configure and install an application")
|
||||
install_parser.add_argument("app")
|
||||
install_parser.add_argument("--host", default="auto", help="'auto'/'local', or root@IP for development")
|
||||
@@ -682,6 +684,18 @@ def main(argv: list[str] | None = None) -> int:
|
||||
if args.command == "show":
|
||||
print(_template_summary_text(catalog.compose(args.app)))
|
||||
return 0
|
||||
if args.command == "open":
|
||||
item = next((item for item in _installable(catalog.load_index()["applications"])
|
||||
if item["id"] == args.app), None)
|
||||
ui = interactive_ui()
|
||||
if item is None:
|
||||
ui.message(translate("This application is not in the OCI catalog."))
|
||||
return 1
|
||||
try:
|
||||
_app_detail(catalog, ui, item)
|
||||
except UserCancelled:
|
||||
pass
|
||||
return 0
|
||||
if args.command == "install":
|
||||
template = catalog.compose(args.app)
|
||||
if not template["compatibility"]["automatic_install_candidate"]:
|
||||
|
||||
@@ -12,6 +12,7 @@ import tempfile
|
||||
|
||||
from . import images
|
||||
from .i18n import N_, source_text, translate
|
||||
from .ui import menu_size
|
||||
|
||||
STATUS_LABELS = {'installed': N_('installed'), 'failed': N_('failed'), 'updating': N_('updating'),
|
||||
'recovering': N_('recovering'), 'installing': N_('installing'),
|
||||
@@ -268,7 +269,7 @@ def _interactive_management(project, ui):
|
||||
else:
|
||||
line += f"\\Z1{translate(STATUS_LABELS.get(r['status'], r['status']))}\\Zn"
|
||||
options.append((str(r['vmid']), f"{line:<72}"))
|
||||
selection = ui.choose(header, options, size=(22, 75, 15), colors=True,
|
||||
selection = ui.choose(header, options, size=menu_size(), colors=True,
|
||||
title=translate('Manage installed OCI applications'))
|
||||
if selection is None:
|
||||
return
|
||||
|
||||
@@ -194,6 +194,13 @@ SUMMARY_WIDTH = 78
|
||||
DETAIL_WINDOW_WIDTH = 90
|
||||
|
||||
|
||||
def menu_size() -> tuple[int, int, int]:
|
||||
"""Height, width and rows of a list of the menu: as tall as the main menu
|
||||
of ProxMenux, cut to the terminal."""
|
||||
height = max(10, min(24, shutil.get_terminal_size((100, 30)).lines - 2))
|
||||
return height, 75, height - 8
|
||||
|
||||
|
||||
@dataclass
|
||||
class DialogUI:
|
||||
"""dialog widgets with the ProxMenux backtitle, used for every menu shown
|
||||
|
||||
Reference in New Issue
Block a user