Reactive list not working #5177
-
I'm trying to make a component to show logs of my TUI. This is the code I have class LogView(ScrollView, Logger):
"""Scrollable log view for displaying messages with colored levels."""
logs = reactive([])
def __init__(self):
super().__init__()
self.styles.border = ("double", "white")
self.border_title = "Logs"
def log_message(self, level: str, message: str):
"""Formats and adds a new message with color coding for warnings."""
timestamp = datetime.now().strftime("%H:%M:%S")
level_prefix = level[0]
level_color = "red" if level == "error" else "yellow" if level == "warn" else "white"
formatted_message = f"{timestamp} [{level_color}]{level_prefix}[/]: {message}"
# Add to log list and update the display
self.logs.append(formatted_message)
def render(self) -> str:
return "\n".join(self.logs)
def info(self, message: str):
self.log_message("info", message)
def warn(self, message: str):
self.log_message("warn", message)
def error(self, message: str):
self.log_message("error", message) But when I use the |
Beta Was this translation helpful? Give feedback.
Answered by
willmcgugan
Oct 25, 2024
Replies: 1 comment
-
This should help explain it, and give you a solution... https://textual.textualize.io/guide/reactivity/#mutable-reactives |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MrNemo64
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should help explain it, and give you a solution... https://textual.textualize.io/guide/reactivity/#mutable-reactives