core: use Kitty encoding if enabled

This commit is contained in:
Mitchell Hashimoto
2023-08-17 09:02:43 -07:00
parent fb9dc74b29
commit 37daf02804
2 changed files with 13 additions and 3 deletions

View File

@ -1037,11 +1037,12 @@ pub fn keyCallback(
.cursor_key_application = t.modes.get(.cursor_keys),
.keypad_key_application = t.modes.get(.keypad_keys),
.modify_other_keys_state_2 = t.flags.modify_other_keys_2,
.kitty_flags = t.screen.kitty_keyboard.current(),
};
};
var data: termio.Message.WriteReq.Small.Array = undefined;
const seq = try enc.legacy(&data);
const seq = try enc.encode(&data);
if (seq.len == 0) return false;
_ = self.io_thread.mailbox.push(.{

View File

@ -24,8 +24,17 @@ keypad_key_application: bool = false,
modify_other_keys_state_2: bool = false,
kitty_flags: KittyFlags = .{},
/// Perform the proper encoding depending on the terminal state.
pub fn encode(
self: *const KeyEncoder,
buf: []u8,
) ![]const u8 {
if (self.kitty_flags.int() != 0) return try self.kitty(buf);
return try self.legacy(buf);
}
/// Perform Kitty keyboard protocol encoding of the key event.
pub fn kitty(
fn kitty(
self: *const KeyEncoder,
buf: []u8,
) ![]const u8 {
@ -126,7 +135,7 @@ pub fn kitty(
/// These together combine the legacy protocol because they're all
/// meant to be extensions that do not change any existing behavior
/// and therefore safe to combine.
pub fn legacy(
fn legacy(
self: *const KeyEncoder,
buf: []u8,
) ![]const u8 {