mirror of
https://github.com/neovim/neovim.git
synced 2025-10-15 06:16:08 +00:00
feat(tui): add nvim_ui_send (#35406)
This function allows the Nvim core to write arbitrary data to a TTY connected to a UI's stdout.
This commit is contained in:
@@ -1001,6 +1001,17 @@ void remote_ui_flush(RemoteUI *ui)
|
||||
}
|
||||
}
|
||||
|
||||
void remote_ui_ui_send(RemoteUI *ui, String content)
|
||||
{
|
||||
if (!ui->stdout_tty) {
|
||||
return;
|
||||
}
|
||||
|
||||
MAXSIZE_TEMP_ARRAY(args, 1);
|
||||
ADD_C(args, STRING_OBJ(content));
|
||||
push_call(ui, "ui_send", args);
|
||||
}
|
||||
|
||||
void remote_ui_flush_pending_data(RemoteUI *ui)
|
||||
{
|
||||
ui_flush_buf(ui, false);
|
||||
@@ -1103,3 +1114,17 @@ void remote_ui_event(RemoteUI *ui, char *name, Array args)
|
||||
free_ret:
|
||||
arena_mem_free(arena_finish(&arena));
|
||||
}
|
||||
|
||||
/// Sends arbitrary data to a UI.
|
||||
///
|
||||
/// This sends a "ui_send" event to any UI that has the "stdout_tty" |ui-option| set. UIs are
|
||||
/// expected to write the received data to a connected TTY if one exists.
|
||||
///
|
||||
/// @param channel_id
|
||||
/// @param content Content to write to the TTY
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_ui_send(uint64_t channel_id, String content, Error *err)
|
||||
FUNC_API_SINCE(14)
|
||||
{
|
||||
ui_call_ui_send(content);
|
||||
}
|
||||
|
@@ -46,6 +46,8 @@ void chdir(String path)
|
||||
// Stop event is not exported as such, represented by EOF in the msgpack stream.
|
||||
void stop(void)
|
||||
FUNC_API_NOEXPORT;
|
||||
void ui_send(String content)
|
||||
FUNC_API_SINCE(14) FUNC_API_REMOTE_IMPL;
|
||||
|
||||
// First revision of the grid protocol, used by default
|
||||
void update_fg(Integer fg)
|
||||
|
@@ -1533,6 +1533,19 @@ void tui_default_colors_set(TUIData *tui, Integer rgb_fg, Integer rgb_bg, Intege
|
||||
invalidate(tui, 0, tui->grid.height, 0, tui->grid.width);
|
||||
}
|
||||
|
||||
/// Writes directly to the TTY, bypassing the buffer.
|
||||
void tui_ui_send(TUIData *tui, String content)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
uv_write_t req;
|
||||
uv_buf_t buf = { .base = content.data, .len = UV_BUF_LEN(content.size) };
|
||||
int ret = uv_write(&req, (uv_stream_t *)&tui->output_handle, &buf, 1, NULL);
|
||||
if (ret) {
|
||||
ELOG("uv_write failed: %s", uv_strerror(ret));
|
||||
}
|
||||
uv_run(&tui->write_loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
/// Flushes TUI grid state to a buffer (which is later flushed to the TTY by `flush_buf`).
|
||||
///
|
||||
/// @see flush_buf
|
||||
|
Reference in New Issue
Block a user