Neovim Core ↔ Lua Runtime: Synchronization of Terminal Output
25.5K reputation · 23 Mar 2023, 23:39 UTC
Neovim Core ↔ Lua Runtime: Synchronization of Terminal Output
The goal is to understand how the core C implementation of Neovim’s terminal emulator coordinates with the Lua runtime when a terminal process emits rapid output. In practice, high‑frequency writes can block the main event loop, causing the editor to freeze or lose keystrokes. The current design routes all terminal output through the core’s I/O loop, but Lua cannot directly influence the buffering strategy. This separation raises an unresolved decision: should the core expose a non‑blocking, event‑driven terminal API to Lua?
Key constraints include maintaining backward compatibility with existing plugins that use :term and ensuring that any new API does not introduce race conditions between the core and Lua. The uncertainty lies in whether a unified async model can be implemented without breaking the current line‑buffered interface.
Specific questions for investigation:
- Should Neovim’s core provide a non‑blocking terminal output API that Lua can consume?
- How can the Lua runtime be extended to register callbacks for terminal output events without interfering with the core’s event loop?
- What event‑driven design pattern would best avoid stalls while preserving the existing :term command semantics?