Repository navigation
v0.18.0
Changed — clipboard= may be async
async def copy(text: str) -> bool:
proc = await asyncio.create_subprocess_exec("pbcopy", stdin=asyncio.subprocess.PIPE)
await proc.communicate(text.encode())
return proc.returncode == 0
FlowView(..., clipboard=copy) # awaited; the UI stays live meanwhileThe hook now accepts sync or async (the "await me maybe" pattern), so a sink that shells out to pbcopy / xclip no longer has to block the UI for the lifetime of that process. write_clipboard and yank are async accordingly. Default key bindings are unaffected.
This is the one callback whose result FlowView reports back to the caller, so it can't be fired and forgotten — every other slow-work hook can be scheduled by the caller instead.
Documentation — where slow work belongs
A false promise is corrected. FlowPresenter's docstring claimed presentation "runs inside a Textual worker so a slow presenter never blocks the UI". A worker is an asyncio task on the same loop, so a CPU-bound present — the usual shape, since rendering is pure CPU — holds the loop and freezes the UI. Measured: four 250 ms presents starved a 10 ms heartbeat to 10 ticks where a free loop manages ~121. That is exactly the trap a consumer hit and reported (#10), while the docs pointed the wrong way.
New docs/event-loop.md frames what was missing — FlowView has two kinds of extension point, and they differ completely:
Messages (Highlighted, Selected, Clicked, ReachedTop/Bottom, …) |
Callbacks (present, decorate, on_show, …) |
|
|---|---|---|
may be async |
yes — async def handlers work out of the box |
only present and clipboard |
| when it runs | later, off FlowView's call stack | inline, inside it |
So slow, reactive work belongs in a message handler, where you can simply await. Verified: an async def on_flow_view_highlighted that awaits 150 ms and then mutates the entry works as written — set_current() returns in 0.5 ms and the loop stays live.
The guide also has a per-hook table (async? how hot?), the measured difference between awaiting and merely "being in a worker" (I/O-bound worker: 29/30 heartbeats; CPU-bound: 3/33; thread=True: 35/35), what to do for the sync hooks, and why FlowView will not run your renderable on a thread.
track_visibility, animate_entry and FlowDecorator docstrings now state they are not awaited and show how to start slow work rather than wait for it.
Full Changelog: v0.17.0...v0.18.0