Skip to content
Discussion options

You must be logged in to vote

You will need to make your action concurrent. The Textual way to do this is with the worker API.

Note the addition of the decorator, and call_from_thread.

from subprocess import PIPE, STDOUT, Popen
from textual.app import App
from textual.widgets import Footer, TextLog
from textual import work


class UI(App):
    BINDINGS = [
        ("1", "run", "run"),
    ]

    def compose(self):
        yield TextLog()
        yield Footer()

    @work
    def action_run(self):
        log = self.query_one(TextLog)
        log.write("start")

        args = ["bash", "-c", "echo foo;sleep 3;echo bar"]

        proc = Popen(args, stdout=PIPE, stderr=STDOUT, text=True)
        while proc.poll() is None:…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant