refactor(tui): reorder functions for query and response (#28051)

- Group functions for key encoding together.
- Move the handle_modereport() branch before the handle_unknown_csi()
  branch to match the order of the corresponding functions, but don't
  move handle_term_response() yet, as that will be subject to further
  changes (e.g. for #26744).
This commit is contained in:
zeertzjq 2024-03-27 11:10:28 +08:00 committed by GitHub
parent fc6d713dd8
commit bf7c7adb40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 32 deletions

View File

@ -442,12 +442,12 @@ static void tk_getkeys(TermInput *input, bool force)
forward_modified_utf8(input, &key);
} else if (key.type == TERMKEY_TYPE_MOUSE) {
forward_mouse_event(input, &key);
} else if (key.type == TERMKEY_TYPE_MODEREPORT) {
handle_modereport(input, &key);
} else if (key.type == TERMKEY_TYPE_UNKNOWN_CSI) {
handle_unknown_csi(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);
}
}

View File

@ -189,36 +189,6 @@ void tui_start(TUIData **tui_p, int *width, int *height, char **term, bool *rgb)
*rgb = tui->rgb;
}
void tui_set_key_encoding(TUIData *tui)
FUNC_ATTR_NONNULL_ALL
{
switch (tui->input.key_encoding) {
case kKeyEncodingKitty:
out(tui, S_LEN("\x1b[>1u"));
break;
case kKeyEncodingXterm:
out(tui, S_LEN("\x1b[>4;2m"));
break;
case kKeyEncodingLegacy:
break;
}
}
static void tui_reset_key_encoding(TUIData *tui)
FUNC_ATTR_NONNULL_ALL
{
switch (tui->input.key_encoding) {
case kKeyEncodingKitty:
out(tui, S_LEN("\x1b[<1u"));
break;
case kKeyEncodingXterm:
out(tui, S_LEN("\x1b[>4;0m"));
break;
case kKeyEncodingLegacy:
break;
}
}
/// Request the terminal's mode (DECRQM).
///
/// @see handle_modereport
@ -270,6 +240,36 @@ static void tui_query_kitty_keyboard(TUIData *tui)
out(tui, S_LEN("\x1b[?u\x1b[c"));
}
void tui_set_key_encoding(TUIData *tui)
FUNC_ATTR_NONNULL_ALL
{
switch (tui->input.key_encoding) {
case kKeyEncodingKitty:
out(tui, S_LEN("\x1b[>1u"));
break;
case kKeyEncodingXterm:
out(tui, S_LEN("\x1b[>4;2m"));
break;
case kKeyEncodingLegacy:
break;
}
}
static void tui_reset_key_encoding(TUIData *tui)
FUNC_ATTR_NONNULL_ALL
{
switch (tui->input.key_encoding) {
case kKeyEncodingKitty:
out(tui, S_LEN("\x1b[<1u"));
break;
case kKeyEncodingXterm:
out(tui, S_LEN("\x1b[>4;0m"));
break;
case kKeyEncodingLegacy:
break;
}
}
/// Enable the alternate screen and emit other control sequences to start the TUI.
///
/// This is also called when the TUI is resumed after being suspended. We reinitialize all state