Replies: 2 comments
|
Probably, the method create_pipe_input() is the starting point to learn python-prompt-toolkit IPC |
|
create_pipe_input() is useful for injecting terminal input into prompt_toolkit (and especially for tests/SSH/telnet-style sessions), but it is not a general IPC transport for arbitrary subprocess stdout/stderr. For an external process, I would keep the process I/O and the TUI as separate layers. prompt_toolkit 3 runs on asyncio, so start/read the subprocess with asyncio's subprocess APIs (or another async process abstraction), have one task consume each stdout/stderr stream, update the model/buffers shown by your controls, and call app.invalidate() when external state changes. Application.invalidate() is explicitly thread-safe if a producer happens to live in another thread. For sending data to the child, write to the subprocess stdin rather than feeding a PipeInput. PipeInput represents keystrokes/input events for the prompt_toolkit application; conflating it with child stdin makes focus, key bindings and terminal escape handling much harder to reason about. For many parallel data sources, the same model scales: one async reader task per source feeds a queue/model; the UI renders that model. Keep blocking reads off the UI event loop. If a library only exposes blocking descriptors, bridge them with an executor/thread and schedule model updates back into the application's loop. patch_stdout/run_in_terminal solve a different problem: allowing ordinary terminal output while prompt_toolkit owns the screen. They are useful for logs, but for a full-screen pane displaying process output, updating a control/buffer and invalidating is the cleaner architecture. So there isn't a prompt_toolkit-native IPC protocol analogous to urwid watch_pipe that you need to route all processes through; integrate the OS/process I/O with asyncio and use prompt_toolkit for input/rendering. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey. Would you explain how to integrate a ppt tui with the input and output of an external process to display and send data to? And of course the multiple process handling is the most significant thing to comprehend as usually we deal with many parallel data sources.
For instance, urwid allows it woth the loop method urwid.MainLoop.watch_pipe
All reactions