Fix multi-line background fill using Text.stylize
This commit is contained in:
@@ -14,15 +14,15 @@ console = Console()
|
|||||||
# Define the emoji pattern and coloring function
|
# Define the emoji pattern and coloring function
|
||||||
emoji_pattern = re.compile(
|
emoji_pattern = re.compile(
|
||||||
r'('
|
r'('
|
||||||
r'\U0001F600-\U0001F64F' # emoticons
|
r' \U0001F600-\U0001F64F' # emoticons
|
||||||
r'\U0001F300-\U0001F5FF' # symbols & pictographs
|
r' \U0001F300-\U0001F5FF' # symbols & pictographs
|
||||||
r'\U0001F680-\U0001F6FF' # transport & map symbols
|
r' \U0001F680-\U0001F6FF' # transport & map symbols
|
||||||
r'\U0001F1E0-\U0001F1FF' # flags (iOS)
|
r' \U0001F1E0-\U0001F1FF' # flags (iOS)
|
||||||
r'\u2702-\u27B0' # Dingbats
|
r' \u2702-\u27B0' # Dingbats
|
||||||
r'\u24C2-\u2B55' # Enclosed characters
|
r' \u24C2-\u2B55' # Enclosed characters
|
||||||
r'\U0001F900-\U0001F9FF' # Supplemental Symbols & Pictographs
|
r' \U0001F900-\U0001F9FF' # Supplemental Symbols & Pictographs
|
||||||
r'\u200D' # ZWJ
|
r' \u200D' # ZWJ
|
||||||
r'\uFE0F' # VS-16
|
r' \uFE0F' # VS-16
|
||||||
r')+', flags=re.UNICODE)
|
r')+', flags=re.UNICODE)
|
||||||
|
|
||||||
def colour_emoji(txt):
|
def colour_emoji(txt):
|
||||||
@@ -109,8 +109,7 @@ def main():
|
|||||||
user_color = get_user_color(author_channel_id)
|
user_color = get_user_color(author_channel_id)
|
||||||
username_style = Style(color=user_color, bold=True)
|
username_style = Style(color=user_color, bold=True)
|
||||||
|
|
||||||
# Format message for terminal
|
# Create a Text object for the entire message
|
||||||
# Use rich.text.Text to build the message with styles
|
|
||||||
full_message_text = Text()
|
full_message_text = Text()
|
||||||
full_message_text.append(f"[{username_style}]{author_display_name}[/]: ")
|
full_message_text.append(f"[{username_style}]{author_display_name}[/]: ")
|
||||||
full_message_text.append(message_text)
|
full_message_text.append(message_text)
|
||||||
@@ -118,12 +117,12 @@ def main():
|
|||||||
# Alternate background styles
|
# Alternate background styles
|
||||||
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
||||||
|
|
||||||
# Create a Text object for the entire line with the background style
|
# Apply the background style to the entire Text object
|
||||||
# Then pad it to the full console width
|
full_message_text.stylize(background_style)
|
||||||
line_to_print = Text.assemble(full_message_text, style=background_style)
|
|
||||||
line_to_print.pad_to_width(console.width, style=background_style)
|
|
||||||
|
|
||||||
console.print(line_to_print, overflow="crop")
|
# Print the message, letting rich handle wrapping and filling the width
|
||||||
|
# rich will automatically apply the background to wrapped lines if styled on the Text object
|
||||||
|
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")
|
log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {full_message_text.plain}\n")
|
||||||
message_count += 1
|
message_count += 1
|
||||||
|
|
||||||
@@ -139,4 +138,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()
|
||||||
|
|||||||
Reference in New Issue
Block a user