Make MsgLevelType.style() return a typed MsgLevelStyle enum

Replace the bare style strings returned by style() with a MsgLevelStyle
StrEnum so the values are type-checked. Being a StrEnum, the members stay
plain strings and pass straight into Text.append(style=...), so no call
sites change.
This commit is contained in:
Softer 2026-06-07 23:19:28 +03:00
parent a44edabf2f
commit be8c19fa4d
1 changed files with 13 additions and 6 deletions

View File

@ -2,29 +2,36 @@ from __future__ import annotations
from collections.abc import Awaitable, Callable, Iterable
from dataclasses import dataclass, field
from enum import Enum, auto
from enum import Enum, StrEnum, auto
from functools import cached_property
from typing import Any, ClassVar, Self, override
from archinstall.lib.translationhandler import tr
class MsgLevelStyle(StrEnum):
White = 'white'
Green = 'green'
Yellow = 'bright_yellow'
Red = 'red'
class MsgLevelType(Enum):
MsgNone = auto()
MsgInfo = auto()
MsgWarning = auto()
MsgError = auto()
def style(self) -> str:
def style(self) -> MsgLevelStyle:
match self:
case MsgLevelType.MsgNone:
return 'white'
return MsgLevelStyle.White
case MsgLevelType.MsgInfo:
return 'green'
return MsgLevelStyle.Green
case MsgLevelType.MsgWarning:
return 'bright_yellow'
return MsgLevelStyle.Yellow
case MsgLevelType.MsgError:
return 'red'
return MsgLevelStyle.Red
@dataclass