From cceb0826318d00497d6ff4840e39e76e979027f8 Mon Sep 17 00:00:00 2001 From: Ramforth Date: Thu, 30 Oct 2025 19:14:51 +0100 Subject: [PATCH] Implement alternating full-width background for chat messages --- pytchat_listener.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pytchat_listener.py b/pytchat_listener.py index 9f6b4e3..e0de084 100644 --- a/pytchat_listener.py +++ b/pytchat_listener.py @@ -61,15 +61,23 @@ def main(): # Apply emoji coloring using the new function message_text = colour_emoji(message_text) - # Alternate background styles - background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A") - # Simple color for username (can be expanded to unique colors per user) username_style = Style(color="#4CAF50", bold=True) - # Format message for terminal and log file + # Format message for terminal formatted_message = f"[{username_style}]{author_display_name}[/]: {message_text}" - console.print(formatted_message, style=background_style) + + # Calculate padding to fill terminal width + # rich handles rendering, so we need to calculate the visible width of the string + # and pad it. This is a simplified approach, rich's Panel might be better for complex layouts. + rendered_length = console.measure(formatted_message).cell_len + padding = max(0, console.width - rendered_length) + padded_message = f"{formatted_message}{' ' * padding}" + + # Alternate background styles + background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A") + + console.print(padded_message, style=background_style, overflow="crop") log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {formatted_message}\n") message_count += 1 @@ -85,4 +93,4 @@ def main(): console.print(f"[green]Chat log saved to {log_filename}[/green]") if __name__ == '__main__': - main() \ No newline at end of file + main()