Archived
1
1
Fork 0

fix logs: add newlines for dark toggle/screenshot msgs

This commit is contained in:
Josh Lay 2023-09-03 22:47:41 -05:00
parent e2f0ace30a
commit 21921cfda6
Signed by: jlay
GPG key ID: B265E45CACAD108A

View file

@ -250,14 +250,28 @@ class app(App): # pylint: disable=invalid-name
yield Container(self.stats_widget) yield Container(self.stats_widget)
yield Footer() yield Footer()
def update_log(self, message: str, show_ts: bool = True) -> None:
"""Update the TextLog widget with a new message.
Highest Textual version-requiring widget; >=0.32.0
Should be more performant than the old TextLog widget
Args:
message (str): The message to be added to the logging widget on the 'Logs' tab.
show_ts (bool, optional): If True (default), appends a timestamp to the message.
"""
if show_ts:
message = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}"
self.stats_widget.text_log.write_line(message)
@work(exclusive=True) @work(exclusive=True)
async def action_custom_dark(self) -> None: async def action_custom_dark(self) -> None:
"""An action to toggle dark mode. """An action to toggle dark mode.
Wraps 'action_toggle_dark' with our logging""" Wraps 'action_toggle_dark' with our logging"""
self.app.dark = not self.app.dark self.app.dark = not self.app.dark
# inline conditional due to how Textual doesn't pretty notifs. for us like TextLog # with new log widget... styling doesn't get rendered, disabling. makes notifications look nice
message = f"[bold]Dark side: [italic][{'green' if self.app.dark else 'red'}]{self.app.dark}" # message = f"[bold]Dark side: [italic][{'green' if self.app.dark else 'red'}]{self.app.dark}"
message = f"Dark side: {self.app.dark}"
self.notify(message) self.notify(message)
self.update_log(message) self.update_log(message)
@ -284,14 +298,10 @@ class app(App): # pylint: disable=invalid-name
# take the screenshot, recording the path for logging/notification # take the screenshot, recording the path for logging/notification
outpath = self.save_screenshot(path=screen_dir, filename=screen_name) outpath = self.save_screenshot(path=screen_dir, filename=screen_name)
# construct the log/notification message, then show it # construct the log/notification message, then show it
message = f"[bold]Path: [/]'[green]{outpath}[/]'" message = f"Path: '{outpath}'"
self.notify(message, title='Screenshot captured', timeout=3.0) self.notify(message, title='Screenshot captured', timeout=3.0)
self.update_log(message) self.update_log(message)
def update_log(self, message: str) -> None:
"""Update the TextLog widget with a new message."""
self.stats_widget.text_log.write(message)
def action_custom_tab(self) -> None: def action_custom_tab(self) -> None:
"""Toggle between the 'Stats' and 'Logs' tabs""" """Toggle between the 'Stats' and 'Logs' tabs"""
# walk/cycle the tabs # walk/cycle the tabs