-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.py
46 lines (36 loc) · 1.11 KB
/
console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import subprocess
from textual import work
from textual.app import App, ComposeResult
from textual.widgets import Log
class MyLog(Log):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.border_title = "Console"
class ConsoleApp(App):
CSS = """
#console {
border: double lightgreen;
}
"""
def compose(self) -> ComposeResult:
yield MyLog(id="console")
async def on_mount(self) -> None:
self.run_process()
@work(thread=True)
def run_process(self) -> None:
console: MyLog = self.query_one("#console")
with subprocess.Popen(
"python -m rich.progress",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
) as proc:
while True:
output = proc.stdout.readline()
if output == "" and proc.poll() is not None:
break
self.call_from_thread(console.write, output)
if __name__ == "__main__":
app = ConsoleApp()
app.run()