Implement alternating full-width background for chat messages

This commit is contained in:
2025-10-30 19:14:51 +01:00
parent 99ed27a8b7
commit cceb082631

View File

@@ -61,15 +61,23 @@ def main():
# Apply emoji coloring using the new function # Apply emoji coloring using the new function
message_text = colour_emoji(message_text) 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) # Simple color for username (can be expanded to unique colors per user)
username_style = Style(color="#4CAF50", bold=True) 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}" 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") log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {formatted_message}\n")
message_count += 1 message_count += 1
@@ -85,4 +93,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()