mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
feat(tui): parse CSI subparams in termkey (#29805)
libtermkey does not know how to parse CSI subparameters (parameters separated by ':', ASCII 0x3A) and currently just ignores them. However, many important CSI sequences sent by the terminal make use of subparameters, most notably key events when using the kitty keyboard protocol [1]. Enabling subparameters is a prerequisite for expanding kitty keyboard protocol support in Neovim. Concretely, we do this by returning pointers into the internal termkey buffer for each CSI parameter rather than parsing them into integers directly. When a caller wants to actually use the parameter as an integer, they must call termkey_interpret_csi_param, which parses the full parameter string into an integer parameter and zero or more subparameters. The pointers into the internal buffer will become invalidated when new input arrives from the terminal so it is important that the individual params are used and parsed right away. All of our code (and libtermkey's code) does this, so this is fine for now, but is something to keep in mind moving forward. [1]: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
This commit is contained in:
@@ -596,10 +596,10 @@ static void handle_unknown_csi(TermInput *input, const TermKeyKey *key)
|
||||
{
|
||||
// There is no specified limit on the number of parameters a CSI sequence can
|
||||
// contain, so just allocate enough space for a large upper bound
|
||||
long args[16];
|
||||
size_t nargs = 16;
|
||||
TermKeyCsiParam params[16];
|
||||
size_t nparams = 16;
|
||||
unsigned long cmd;
|
||||
if (termkey_interpret_csi(input->tk, key, args, &nargs, &cmd) != TERMKEY_RES_KEY) {
|
||||
if (termkey_interpret_csi(input->tk, key, params, &nparams, &cmd) != TERMKEY_RES_KEY) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -639,12 +639,22 @@ static void handle_unknown_csi(TermInput *input, const TermKeyKey *key)
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (nargs == 5 && args[0] == 48) {
|
||||
// In-band resize event (DEC private mode 2048)
|
||||
int height_chars = (int)args[1];
|
||||
int width_chars = (int)args[2];
|
||||
tui_set_size(input->tui_data, width_chars, height_chars);
|
||||
ui_client_set_size(width_chars, height_chars);
|
||||
if (nparams == 5) {
|
||||
// We only care about the first 3 parameters, and we ignore subparameters
|
||||
long args[3];
|
||||
for (size_t i = 0; i < ARRAY_SIZE(args); i++) {
|
||||
if (termkey_interpret_csi_param(params[i], &args[i], NULL, NULL) != TERMKEY_RES_KEY) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0] == 48) {
|
||||
// In-band resize event (DEC private mode 2048)
|
||||
int height_chars = (int)args[1];
|
||||
int width_chars = (int)args[2];
|
||||
tui_set_size(input->tui_data, width_chars, height_chars);
|
||||
ui_client_set_size(width_chars, height_chars);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
Reference in New Issue
Block a user