Fix multi-line background fill and add user_colors.json error handling
This commit is contained in:
@@ -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()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user