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():
|
def load_user_colors():
|
||||||
global user_color_map
|
global user_color_map
|
||||||
if os.path.exists(USER_COLORS_FILE):
|
if os.path.exists(USER_COLORS_FILE):
|
||||||
with open(USER_COLORS_FILE, 'r') as f:
|
try:
|
||||||
user_color_map = json.load(f)
|
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():
|
def save_user_colors():
|
||||||
with open(USER_COLORS_FILE, 'w') as f:
|
with open(USER_COLORS_FILE, 'w') as f:
|
||||||
@@ -108,7 +112,7 @@ def main():
|
|||||||
# Format message for terminal
|
# Format message for terminal
|
||||||
# Use rich.text.Text to build the message with styles
|
# Use rich.text.Text to build the message with styles
|
||||||
full_message_text = Text()
|
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)
|
full_message_text.append(message_text)
|
||||||
|
|
||||||
# Alternate background styles
|
# Alternate background styles
|
||||||
@@ -116,7 +120,8 @@ def main():
|
|||||||
|
|
||||||
# Print the message, letting rich handle wrapping and filling the width
|
# Print the message, letting rich handle wrapping and filling the width
|
||||||
# The 'width' parameter ensures the background fills the terminal 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")
|
log_file.write(f"{datetime.now().strftime("%H:%M:%S")} {full_message_text.plain}\n")
|
||||||
message_count += 1
|
message_count += 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user