pySim.log: apply cmd2 colors through _style()

The color scheme takes either
- a raw escape sequence like "\033[33m" (pySim-read,
pySim-prog, contrib/csv-to-pgsql.py)
- a cmd2 color object (pySim-shell)

Color of cmd2 >= 3.0.0 is a StrEnum, which led to
pySim-shell warnings like

  yellowWARNING: EF.DIR seems to be empty!

with a stray reset at the end.

Fixed by exclusing Enum from the raw sequence branch.

Change-Id: I8bae9fc3c54f1dab481d743d3b68e32e9d09267a
This commit is contained in:
Eric Wild
2026-09-23 17:51:04 +02:00
parent aeba4004de
commit 2b7abdcf96
2 changed files with 24 additions and 1 deletions
+2 -1
View File
@@ -24,6 +24,7 @@
#
import logging
import enum
import cmd2
from packaging import version
@@ -126,7 +127,7 @@ class PySimLogger:
formatted_message = logging.Formatter.format(PySimLogger.__formatter, record)
color = PySimLogger.colors.get(record.levelno)
if color:
if isinstance(color, str):
if isinstance(color, str) and not isinstance(color, enum.Enum):
PySimLogger.print_callback(color + formatted_message + "\033[0m")
else:
PySimLogger.print_callback(_style(formatted_message, fg = color))