mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
feat(tui): built UI sets client info
This commit is contained in:
parent
a0d8c2b86e
commit
7ed9fd0573
@ -1586,6 +1586,7 @@ Array nvim_get_api_info(uint64_t channel_id, Arena *arena)
|
||||
///
|
||||
/// @param attributes Arbitrary string:string map of informal client properties.
|
||||
/// Suggested keys:
|
||||
/// - "pid": Process id.
|
||||
/// - "website": Client homepage URL (e.g. GitHub repository)
|
||||
/// - "license": License description ("Apache 2", "GPLv3", "MIT", …)
|
||||
/// - "logo": URI or path to image, preferably small logo or icon.
|
||||
@ -1644,9 +1645,8 @@ void nvim_set_client_info(uint64_t channel_id, String name, Dictionary version,
|
||||
/// the key will still be present if a pty is used (e.g. for
|
||||
/// conpty on Windows).
|
||||
/// - "buffer" (optional) Buffer with connected |terminal| instance.
|
||||
/// - "client" (optional) Info about the peer (client on the other end of
|
||||
/// the RPC channel), if provided by it via
|
||||
/// |nvim_set_client_info()|.
|
||||
/// - "client" (optional) Info about the peer (client on the other end of the RPC channel),
|
||||
/// which it provided via |nvim_set_client_info()|.
|
||||
///
|
||||
Dictionary nvim_get_chan_info(uint64_t channel_id, Integer chan, Arena *arena, Error *err)
|
||||
FUNC_API_SINCE(4)
|
||||
|
@ -464,7 +464,7 @@ static void tinput_timer_cb(uv_timer_t *handle)
|
||||
{
|
||||
TermInput *input = handle->data;
|
||||
// If the raw buffer is not empty, process the raw buffer first because it is
|
||||
// processing an incomplete bracketed paster sequence.
|
||||
// processing an incomplete bracketed paste sequence.
|
||||
size_t size = rstream_available(&input->read_stream);
|
||||
if (size) {
|
||||
size_t consumed = handle_raw_buffer(input, true, input->read_stream.read_pos, size);
|
||||
|
@ -182,9 +182,10 @@ bool ui_override(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ui_active(void)
|
||||
/// Gets the number of UIs connected to this server.
|
||||
size_t ui_active(void)
|
||||
{
|
||||
return ui_count > 0;
|
||||
return ui_count;
|
||||
}
|
||||
|
||||
void ui_refresh(void)
|
||||
@ -197,7 +198,7 @@ void ui_refresh(void)
|
||||
int height = INT_MAX;
|
||||
bool ext_widgets[kUIExtCount];
|
||||
bool inclusive = ui_override();
|
||||
memset(ext_widgets, ui_active(), ARRAY_SIZE(ext_widgets));
|
||||
memset(ext_widgets, !!ui_active(), ARRAY_SIZE(ext_widgets));
|
||||
|
||||
for (size_t i = 0; i < ui_count; i++) {
|
||||
RemoteUI *ui = uis[i];
|
||||
|
@ -81,12 +81,15 @@ uint64_t ui_client_start_server(int argc, char **argv)
|
||||
return channel->id;
|
||||
}
|
||||
|
||||
/// Attaches this client to the UI channel, and sets its client info.
|
||||
void ui_client_attach(int width, int height, char *term, bool rgb)
|
||||
{
|
||||
//
|
||||
// nvim_ui_attach
|
||||
//
|
||||
MAXSIZE_TEMP_ARRAY(args, 3);
|
||||
ADD_C(args, INTEGER_OBJ(width));
|
||||
ADD_C(args, INTEGER_OBJ(height));
|
||||
|
||||
MAXSIZE_TEMP_DICT(opts, 9);
|
||||
PUT_C(opts, "rgb", BOOLEAN_OBJ(rgb));
|
||||
PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true));
|
||||
@ -94,7 +97,6 @@ void ui_client_attach(int width, int height, char *term, bool rgb)
|
||||
if (term) {
|
||||
PUT_C(opts, "term_name", CSTR_AS_OBJ(term));
|
||||
}
|
||||
|
||||
PUT_C(opts, "term_colors", INTEGER_OBJ(t_colors));
|
||||
if (!ui_client_is_remote) {
|
||||
PUT_C(opts, "stdin_tty", BOOLEAN_OBJ(stdin_isatty));
|
||||
@ -108,6 +110,36 @@ void ui_client_attach(int width, int height, char *term, bool rgb)
|
||||
|
||||
rpc_send_event(ui_client_channel_id, "nvim_ui_attach", args);
|
||||
ui_client_attached = true;
|
||||
|
||||
//
|
||||
// nvim_set_client_info
|
||||
//
|
||||
MAXSIZE_TEMP_ARRAY(args2, 5);
|
||||
ADD_C(args2, CSTR_AS_OBJ("nvim-tui")); // name
|
||||
Object m = api_metadata();
|
||||
Dictionary version = { 0 };
|
||||
assert(m.data.dictionary.size > 0);
|
||||
for (size_t i = 0; i < m.data.dictionary.size; i++) {
|
||||
if (strequal(m.data.dictionary.items[i].key.data, "version")) {
|
||||
version = m.data.dictionary.items[i].value.data.dictionary;
|
||||
break;
|
||||
} else if (i + 1 == m.data.dictionary.size) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
ADD_C(args2, DICTIONARY_OBJ(version)); // version
|
||||
ADD_C(args2, CSTR_AS_OBJ("ui")); // type
|
||||
// We don't send api_metadata.functions as the "methods" because:
|
||||
// 1. it consumes memory.
|
||||
// 2. it is unlikely to be useful, since the peer can just call `nvim_get_api`.
|
||||
// 3. nvim_set_client_info expects a dict instead of an array.
|
||||
ADD_C(args2, ARRAY_OBJ((Array)ARRAY_DICT_INIT)); // methods
|
||||
MAXSIZE_TEMP_DICT(info, 9); // attributes
|
||||
PUT_C(info, "website", CSTR_AS_OBJ("https://neovim.io"));
|
||||
PUT_C(info, "license", CSTR_AS_OBJ("Apache 2"));
|
||||
PUT_C(info, "pid", INTEGER_OBJ(os_get_pid()));
|
||||
ADD_C(args2, DICTIONARY_OBJ(info)); // attributes
|
||||
rpc_send_event(ui_client_channel_id, "nvim_set_client_info", args2);
|
||||
}
|
||||
|
||||
void ui_client_detach(void)
|
||||
|
Loading…
Reference in New Issue
Block a user