diff --git a/pytchat_listener.py b/pytchat_listener.py index a94c893..b35059a 100644 --- a/pytchat_listener.py +++ b/pytchat_listener.py @@ -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 @@ -138,4 +138,4 @@ def main(): console.print(f"[green]Chat log saved to {log_filename}[/green]") if __name__ == '__main__': - main() + main() \ No newline at end of file