From 3d68a8efc740524735224b696d8668f15c525c42 Mon Sep 17 00:00:00 2001 From: Ramforth Date: Thu, 30 Oct 2025 19:38:07 +0100 Subject: [PATCH] Fix multi-line background fill and add user_colors.json error handling --- pytchat_listener.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pytchat_listener.py b/pytchat_listener.py index e4bfccd..2b9373a 100644 --- a/pytchat_listener.py +++ b/pytchat_listener.py @@ -43,8 +43,12 @@ user_color_map = {} def load_user_colors(): global user_color_map if os.path.exists(USER_COLORS_FILE): - with open(USER_COLORS_FILE, 'r') as f: - user_color_map = json.load(f) + try: + with open(USER_COLORS_FILE, 'r') as f: + user_color_map = json.load(f) + except json.JSONDecodeError: + console.print(f"[red]Error loading {USER_COLORS_FILE}. File might be corrupted. Starting with empty colors.[/red]") + user_color_map = {} def save_user_colors(): with open(USER_COLORS_FILE, 'w') as f: @@ -108,7 +112,7 @@ def main(): # Format message for terminal # Use rich.text.Text to build the message with styles full_message_text = Text() - full_message_text.append(f"{author_display_name}: ", style=username_style) + full_message_text.append(f"[{username_style}]{author_display_name}[/]: ") full_message_text.append(message_text) # Alternate background styles @@ -116,7 +120,8 @@ def main(): # Print the message, letting rich handle wrapping and filling the width # The 'width' parameter ensures the background fills the terminal width - console.print(full_message_text, style=background_style, width=console.width, overflow="crop") + # We remove the manual padding and rely on rich's internal handling. + console.print(full_message_text, style=background_style, width=console.width) log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {full_message_text.plain}\n") message_count += 1 @@ -132,4 +137,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()