From 139bd105e60c946f5636d9cfd85d44896e61e920 Mon Sep 17 00:00:00 2001 From: Softer Date: Sat, 6 Jun 2026 13:00:13 +0300 Subject: [PATCH] Move level-to-style mapping into MsgLevelType.style() method Replace the module-level _LEVEL_STYLE dict in components.py with a style() method on the MsgLevelType enum, following the project convention of encapsulating type-bound logic on the type itself. --- archinstall/tui/components.py | 12 ++---------- archinstall/tui/menu_item.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/archinstall/tui/components.py b/archinstall/tui/components.py index bea36394..0c7f0319 100644 --- a/archinstall/tui/components.py +++ b/archinstall/tui/components.py @@ -27,14 +27,6 @@ from archinstall.tui.result import Result, ResultType ValueT = TypeVar('ValueT') -_LEVEL_STYLE: dict[MsgLevelType, str] = { - MsgLevelType.MsgNone: '', - MsgLevelType.MsgError: 'red', - MsgLevelType.MsgWarning: 'bright_yellow', - MsgLevelType.MsgInfo: 'green', -} - - def _update_preview(widget: Label, result: str | PreviewResult | list[PreviewResult] | None) -> None: if result is None: widget.update('') @@ -43,14 +35,14 @@ def _update_preview(widget: Label, result: str | PreviewResult | list[PreviewRes if isinstance(result, str): widget.update(result) elif isinstance(result, PreviewResult): - text = Text(result.message, style=_LEVEL_STYLE[result.msg_level]) + text = Text(result.message, style=result.msg_level.style()) widget.update(text) else: text = Text() for i, section in enumerate(result): if i > 0: text.append('\n\n') - text.append(section.message, style=_LEVEL_STYLE[section.msg_level]) + text.append(section.message, style=section.msg_level.style()) widget.update(text) diff --git a/archinstall/tui/menu_item.py b/archinstall/tui/menu_item.py index 0e3552fe..c3b01606 100644 --- a/archinstall/tui/menu_item.py +++ b/archinstall/tui/menu_item.py @@ -15,6 +15,17 @@ class MsgLevelType(Enum): MsgWarning = auto() MsgError = auto() + def style(self) -> str: + match self: + case MsgLevelType.MsgNone: + return 'white' + case MsgLevelType.MsgInfo: + return 'green' + case MsgLevelType.MsgWarning: + return 'bright_yellow' + case MsgLevelType.MsgError: + return 'red' + @dataclass class PreviewResult: