mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-01 10:22:08 +00:00
fix(oci): show the update list at the size of the other menus
This commit is contained in:
@@ -172,7 +172,7 @@ class TerminalUI:
|
|||||||
return options[int(selected) - 1][0]
|
return options[int(selected) - 1][0]
|
||||||
return None
|
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)]
|
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,
|
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)
|
result = self._run(widget, title)
|
||||||
return result.stderr.strip() if result.returncode == 0 else None
|
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))
|
terminal = shutil.get_terminal_size((100, 30))
|
||||||
height = min(max(len(options) + 9, 14), terminal.lines - 2)
|
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 = ['--ok-label', ok_label] if ok_label else []
|
||||||
widget += ["--separate-output", "--checklist", f"\n{text}", str(height), str(MENU_WIDTH),
|
widget += ["--separate-output", "--checklist", f"\n{text}", str(height), str(width), str(rows)]
|
||||||
str(max(4, min(len(options), height - 8)))]
|
|
||||||
for tag, label in options:
|
for tag, label in options:
|
||||||
widget += [tag, label, "on" if tag in defaults else "off"]
|
widget += [tag, label, "on" if tag in defaults else "off"]
|
||||||
result = self._run(widget, title)
|
result = self._run(widget, title)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .i18n import translate
|
from .i18n import translate
|
||||||
from .ui import UserCancelled
|
from .ui import UserCancelled, menu_size
|
||||||
|
|
||||||
|
|
||||||
class UpdateCheck:
|
class UpdateCheck:
|
||||||
@@ -166,7 +166,8 @@ def select_updates(project, ui, available):
|
|||||||
try:
|
try:
|
||||||
picked = ui.checklist(
|
picked = ui.checklist(
|
||||||
translate('Press Space to select applications to update. Select all includes every application in this list.'),
|
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:
|
except UserCancelled:
|
||||||
return False
|
return False
|
||||||
selected = [row for row in available if 'all' in picked or str(row['vmid']) in picked]
|
selected = [row for row in available if 'all' in picked or str(row['vmid']) in picked]
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ class SelectionTests(unittest.TestCase):
|
|||||||
def test_selection_has_an_update_button_and_no_extra_action(self):
|
def test_selection_has_an_update_button_and_no_extra_action(self):
|
||||||
result, ui, run = self.select([])
|
result, ui, run = self.select([])
|
||||||
self.assertEqual(ui.checklist.call_args.kwargs['ok_label'], 'Update')
|
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.assertNotIn('extra_button', ui.checklist.call_args.kwargs)
|
||||||
self.assertFalse(result); ui.review.assert_not_called(); run.assert_not_called()
|
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.assertNotIn('--extra-button', widget)
|
||||||
self.assertEqual(widget[widget.index('--ok-label') + 1], 'Update')
|
self.assertEqual(widget[widget.index('--ok-label') + 1], 'Update')
|
||||||
self.assertNotIn('on', widget)
|
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):
|
class MainMenuTests(unittest.TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user