diff --git a/bec_lib/bec_lib/messaging_services.py b/bec_lib/bec_lib/messaging_services.py index 2711701c5..50138a76c 100644 --- a/bec_lib/bec_lib/messaging_services.py +++ b/bec_lib/bec_lib/messaging_services.py @@ -36,12 +36,13 @@ def __init__(self, service: MessagingService, scope: str | list[str] | None = No self._scope = scope self._content = [] - def add_text(self, text: str) -> Self: + def add_text(self, text: str, **kwargs) -> Self: """ Add text to the message object. Args: text (str): The text to add. + **kwargs: Additional keyword arguments for specific messaging services. Returns: MessageObject: The updated message object. @@ -268,6 +269,43 @@ class SciLogMessageServiceObject(MessageServiceObject): A class representing a message object for the SciLog messaging service. """ + def add_text( + self, + text: str, + bold: bool = False, + italic: bool = False, + color: str | None = None, + **kwargs, + ) -> Self: + """ + Add text to the SciLog message with optional inline HTML formatting. + + When any formatting option is supplied the text is wrapped in a ``
``
+ paragraph so SciLog renders it correctly.
+
+ Args:
+ text: The text content.
+ bold: Wrap the text in ````.
+ italic: Wrap the text in ````.
+ color: Highlight colour using SciLog's pen marks (e.g. ``"red"``,
+ ``"yellow"``, ``"green"``, ``"blue"``, ``"pink"``).
+
+ Returns:
+ SciLogMessageServiceObject: The updated message object.
+
+ Examples:
+ >>> msg.add_text("Checks failed", bold=True, color="red")
+ """
+ if bold or italic or color:
+ if bold:
+ text = f"{text}"
+ if italic:
+ text = f"{text}"
+ if color:
+ text = f'{text}'
+ text = f" {text} hello hello warn Beamline checks failed