-
|
Hey guys! I would greatly appreciate a simple example of how to utilize the "begin_capture_print" function to catch stdout/stderr. My plan is to send console output to a RichLog widget but can't get it to work. |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Jan 11, 2024
Replies: 1 comment 2 replies
-
|
Often, if you can't get something to work, it can be a good idea to show what you tried and say how it failed so we can help correct any misunderstanding. To start with, here's an example of an application that logs the time every second, capturing a from datetime import datetime
from textual.app import App, ComposeResult
from textual.events import Print
from textual.widgets import Log
class PrintLog(Log):
def on_mount(self) -> None:
self.begin_capture_print()
def on_print(self, event: Print) -> None:
self.write(event.text)
class PrintLogApp(App[None]):
def compose(self) -> ComposeResult:
yield PrintLog()
def print_time(self) -> None:
print(str(datetime.now()))
def on_mount(self) -> None:
self.set_interval(1.0, self.print_time)
if __name__ == "__main__":
PrintLogApp().run() |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
davep
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Often, if you can't get something to work, it can be a good idea to show what you tried and say how it failed so we can help correct any misunderstanding.
To start with, here's an example of an application that logs the time every second, capturing a
printto do it: