Add annotations to pytchat_listener.py for clarity
This commit is contained in:
@@ -79,7 +79,7 @@ def main():
|
||||
log_file = open(log_filename, "w", encoding="utf-8")
|
||||
console.print(f"[green]Chat will be logged to {log_filename}[/green]")
|
||||
|
||||
# Load existing user colors
|
||||
# Load existing user colors from user_colors.json
|
||||
load_user_colors()
|
||||
|
||||
try:
|
||||
@@ -113,6 +113,7 @@ def main():
|
||||
username_text = Text(f"{author_display_name}: ", style=username_style)
|
||||
|
||||
# Create a Text object for the message, interpreting rich markup
|
||||
# This allows rich markup (e.g., [bold]) within the message text itself to be rendered.
|
||||
message_text_rich = Text.from_markup(message_text)
|
||||
|
||||
# Assemble the full message
|
||||
@@ -122,9 +123,13 @@ def main():
|
||||
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
||||
|
||||
# Apply the background style to the entire Text object
|
||||
# This ensures the background color extends across the full width of the terminal
|
||||
# for all lines of the message, even if it wraps.
|
||||
full_message_text.stylize(background_style)
|
||||
|
||||
# Print the message, letting rich handle wrapping and filling the width
|
||||
# The 'width' parameter ensures the background fills the terminal width.
|
||||
# 'overflow="crop"' prevents text from wrapping beyond the terminal width.
|
||||
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
|
||||
@@ -141,4 +146,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