aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-11-16 11:12:42 -0600
committerGitHub <noreply@github.com>2023-11-16 11:12:42 -0600
commitb4b7ca2d548a1cc1a2cd8c48e5c93478811bd275 (patch)
treec129a344b53a87d8e31f31ec50da7905158e1495 /src
parentdc3f84bf4f94d0389f74991c555c3e76c2ea67f6 (diff)
downloadrneovim-b4b7ca2d548a1cc1a2cd8c48e5c93478811bd275.tar.gz
rneovim-b4b7ca2d548a1cc1a2cd8c48e5c93478811bd275.tar.bz2
rneovim-b4b7ca2d548a1cc1a2cd8c48e5c93478811bd275.zip
feat(tui): support DCS responses in TermResponse event (#26061)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/ui.c15
-rw-r--r--src/nvim/tui/input.c30
2 files changed, 29 insertions, 16 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 1483650739..c1fc986029 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -513,12 +513,13 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa
ui->pum_pos = true;
}
-/// Tells Nvim when a terminal event has occurred: sets |v:termresponse| and fires |TermResponse|.
+/// Tells Nvim when a terminal event has occurred
///
/// The following terminal events are supported:
///
-/// - "osc_response": The terminal sent a OSC response sequence to Nvim. The
-/// payload is the received OSC sequence.
+/// - "termresponse": The terminal sent an OSC or DCS response sequence to
+/// Nvim. The payload is the received response. Sets
+/// |v:termresponse| and fires |TermResponse|.
///
/// @param channel_id
/// @param event Event name
@@ -527,14 +528,14 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, Floa
void nvim_ui_term_event(uint64_t channel_id, String event, Object value, Error *err)
FUNC_API_SINCE(12) FUNC_API_REMOTE_ONLY
{
- if (strequal("osc_response", event.data)) {
+ if (strequal("termresponse", event.data)) {
if (value.type != kObjectTypeString) {
- api_set_error(err, kErrorTypeValidation, "osc_response must be a string");
+ api_set_error(err, kErrorTypeValidation, "termresponse must be a string");
return;
}
- const String osc_response = value.data.string;
- set_vim_var_string(VV_TERMRESPONSE, osc_response.data, (ptrdiff_t)osc_response.size);
+ const String termresponse = value.data.string;
+ set_vim_var_string(VV_TERMRESPONSE, termresponse.data, (ptrdiff_t)termresponse.size);
apply_autocmds_group(EVENT_TERMRESPONSE, NULL, NULL, false, AUGROUP_ALL, NULL, NULL, &value);
}
}
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index ce17d22578..de4afa68cf 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -476,8 +476,8 @@ static void tk_getkeys(TermInput *input, bool force)
}
}
}
- } else if (key.type == TERMKEY_TYPE_OSC) {
- handle_osc_event(input, &key);
+ } else if (key.type == TERMKEY_TYPE_OSC || key.type == TERMKEY_TYPE_DCS) {
+ handle_term_response(input, &key);
} else if (key.type == TERMKEY_TYPE_MODEREPORT) {
handle_modereport(input, &key);
}
@@ -578,22 +578,34 @@ static HandleState handle_bracketed_paste(TermInput *input)
return kNotApplicable;
}
-static void handle_osc_event(TermInput *input, const TermKeyKey *key)
+static void handle_term_response(TermInput *input, const TermKeyKey *key)
FUNC_ATTR_NONNULL_ALL
{
const char *str = NULL;
if (termkey_interpret_string(input->tk, key, &str) == TERMKEY_RES_KEY) {
assert(str != NULL);
- // Send an event to nvim core. This will update the v:termresponse variable and fire the
- // TermResponse event
+ // Send an event to nvim core. This will update the v:termresponse variable
+ // and fire the TermResponse event
MAXSIZE_TEMP_ARRAY(args, 2);
- ADD_C(args, STATIC_CSTR_AS_OBJ("osc_response"));
+ ADD_C(args, STATIC_CSTR_AS_OBJ("termresponse"));
- // libtermkey strips the OSC bytes from the response. We add it back in so that downstream
- // consumers of v:termresponse can differentiate between OSC and CSI events.
+ // libtermkey strips the OSC/DCS bytes from the response. We add it back in
+ // so that downstream consumers of v:termresponse can differentiate between
+ // the two.
StringBuilder response = KV_INITIAL_VALUE;
- kv_printf(response, "\x1b]%s", str);
+ switch (key->type) {
+ case TERMKEY_TYPE_OSC:
+ kv_printf(response, "\x1b]%s", str);
+ break;
+ case TERMKEY_TYPE_DCS:
+ kv_printf(response, "\x1bP%s", str);
+ break;
+ default:
+ // Key type already checked for OSC/DCS in termkey_interpret_string
+ UNREACHABLE;
+ }
+
ADD_C(args, STRING_OBJ(cbuf_as_string(response.items, response.size)));
rpc_send_event(ui_client_channel_id, "nvim_ui_term_event", args);
kv_destroy(response);