From 5f1aa4cde7e8ede0ac6b46b2bc7909c58cfd1509 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Tue, 20 Oct 2026 00:24:22 +0200 Subject: [PATCH] fix(oci): show the update list at the size of the other menus --- oci/src/proxmenux_oci/ui.py | 10 ++++++---- oci/src/proxmenux_oci/updates.py | 5 +++-- oci/tests/test_update_menu.py | 7 +++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/oci/src/proxmenux_oci/ui.py b/oci/src/proxmenux_oci/ui.py index 1f1b54d0..721b0a19 100644 --- a/oci/src/proxmenux_oci/ui.py +++ b/oci/src/proxmenux_oci/ui.py @@ -172,7 +172,7 @@ class TerminalUI: return options[int(selected) - 1][0] return None - def checklist(self, text, options, defaults, title: str | None = None, ok_label=None): + def checklist(self, text, options, defaults, title: str | None = None, ok_label=None, size=None): return [tag for tag, label in options if self.confirm(label, tag in defaults)] def detail_menu(self, text: str, options: list[tuple[str, str]], default: str | None = None, @@ -374,12 +374,14 @@ class DialogUI: result = self._run(widget, title) return result.stderr.strip() if result.returncode == 0 else None - def checklist(self, text, options, defaults, title: str | None = None, ok_label=None): + def checklist(self, text, options, defaults, title: str | None = None, ok_label=None, size=None): terminal = shutil.get_terminal_size((100, 30)) height = min(max(len(options) + 9, 14), terminal.lines - 2) + width, rows = MENU_WIDTH, max(4, min(len(options), height - 8)) + if size: + height, width, rows = size widget = ['--ok-label', ok_label] if ok_label else [] - widget += ["--separate-output", "--checklist", f"\n{text}", str(height), str(MENU_WIDTH), - str(max(4, min(len(options), height - 8)))] + widget += ["--separate-output", "--checklist", f"\n{text}", str(height), str(width), str(rows)] for tag, label in options: widget += [tag, label, "on" if tag in defaults else "off"] result = self._run(widget, title) diff --git a/oci/src/proxmenux_oci/updates.py b/oci/src/proxmenux_oci/updates.py index f1c95bb7..34b7d623 100644 --- a/oci/src/proxmenux_oci/updates.py +++ b/oci/src/proxmenux_oci/updates.py @@ -10,7 +10,7 @@ import subprocess import sys from .i18n import translate -from .ui import UserCancelled +from .ui import UserCancelled, menu_size class UpdateCheck: @@ -166,7 +166,8 @@ def select_updates(project, ui, available): try: picked = ui.checklist( translate('Press Space to select applications to update. Select all includes every application in this list.'), - choices, defaults, title=translate('Updates available'), ok_label=translate('Update')) + choices, defaults, title=translate('Updates available'), ok_label=translate('Update'), + size=menu_size()) except UserCancelled: return False selected = [row for row in available if 'all' in picked or str(row['vmid']) in picked] diff --git a/oci/tests/test_update_menu.py b/oci/tests/test_update_menu.py index 94dab3c3..cbf196b5 100644 --- a/oci/tests/test_update_menu.py +++ b/oci/tests/test_update_menu.py @@ -61,6 +61,8 @@ class SelectionTests(unittest.TestCase): def test_selection_has_an_update_button_and_no_extra_action(self): result, ui, run = self.select([]) self.assertEqual(ui.checklist.call_args.kwargs['ok_label'], 'Update') + # The same height and width as the OCI main menu. + self.assertEqual(ui.checklist.call_args.kwargs['size'], updates.menu_size()) self.assertNotIn('extra_button', ui.checklist.call_args.kwargs) self.assertFalse(result); ui.review.assert_not_called(); run.assert_not_called() @@ -242,6 +244,11 @@ class DialogTests(unittest.TestCase): self.assertNotIn('--extra-button', widget) self.assertEqual(widget[widget.index('--ok-label') + 1], 'Update') self.assertNotIn('on', widget) + with patch.object(ui, '_run', return_value=SimpleNamespace(returncode=0, stderr='')) as run: + ui.checklist('Updates', [('111', 'App')], [], size=(24, 75, 16)) + widget = run.call_args.args[0] + start = widget.index('--checklist') + self.assertEqual(widget[start + 2:start + 5], ['24', '75', '16']) class MainMenuTests(unittest.TestCase):