Skip to content

How can I use Textual to tail a file and display the output in a Log widget? #5029

Answered by kyrlon
kyrlon asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up doing something like this without adding threads to the code, which I was attempting to avoid. The only caveat I see with this example is if I set the interval faster than a second, the logging displayed gets kind of weird/butchered

from textual.app import App, ComposeResult
from textual.widgets import Log
import os, platform
import subprocess
import time

class LogApp(App):

    def __init__(self, file_name, **kwargs):
        super().__init__(**kwargs)
        self.current = None
        self.curino = None
        self.file_name = file_name

    def compose(self) -> ComposeResult:
        yield Log()

    def on_ready(self) -> None:
        self.logg = self.query_one(Log)
   …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kyrlon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants