Fix rich markup rendering for username style

This commit is contained in:
2025-10-30 19:48:46 +01:00
parent 7052a80afe
commit bda9164f7c

View File

@@ -109,10 +109,11 @@ def main():
user_color = get_user_color(author_channel_id)
username_style = Style(color=user_color, bold=True)
# Create a Text object for the entire message
full_message_text = Text()
full_message_text.append(f"[{username_style}]{author_display_name}[/]: ")
full_message_text.append(message_text)
# Create a Text object for the username and apply style directly
username_text = Text(f"{username_style}]{author_display_name}: ", style=username_style)
# Create a Text object for the full message
full_message_text = Text.assemble(username_text, message_text)
# Alternate background styles
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
@@ -121,7 +122,6 @@ def main():
full_message_text.stylize(background_style)
# Print the message, letting rich handle wrapping and filling the width
# rich will automatically apply the background to wrapped lines if styled on the Text object
console.print(full_message_text, width=console.width, overflow="crop")
log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {full_message_text.plain}\n")
message_count += 1