Fix rich markup rendering for username style
This commit is contained in:
@@ -109,10 +109,11 @@ def main():
|
|||||||
user_color = get_user_color(author_channel_id)
|
user_color = get_user_color(author_channel_id)
|
||||||
username_style = Style(color=user_color, bold=True)
|
username_style = Style(color=user_color, bold=True)
|
||||||
|
|
||||||
# Create a Text object for the entire message
|
# Create a Text object for the username and apply style directly
|
||||||
full_message_text = Text()
|
username_text = Text(f"{username_style}]{author_display_name}: ", style=username_style)
|
||||||
full_message_text.append(f"[{username_style}]{author_display_name}[/]: ")
|
|
||||||
full_message_text.append(message_text)
|
# Create a Text object for the full message
|
||||||
|
full_message_text = Text.assemble(username_text, message_text)
|
||||||
|
|
||||||
# Alternate background styles
|
# Alternate background styles
|
||||||
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
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)
|
full_message_text.stylize(background_style)
|
||||||
|
|
||||||
# Print the message, letting rich handle wrapping and filling the width
|
# 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")
|
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")
|
log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {full_message_text.plain}\n")
|
||||||
message_count += 1
|
message_count += 1
|
||||||
@@ -138,4 +138,4 @@ def main():
|
|||||||
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user