diff --git a/src/Surface.zig b/src/Surface.zig index c16987b70..e9f766385 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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(.{ diff --git a/src/input/KeyEncoder.zig b/src/input/KeyEncoder.zig index 6be1fbdd0..4fa760314 100644 --- a/src/input/KeyEncoder.zig +++ b/src/input/KeyEncoder.zig @@ -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 {