From e7bdda9918a87f74178e15132c2894e29a8bf271 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 4 Sep 2026 09:39:56 -0700 Subject: [PATCH] input: encode F13 through F25 --- src/input/function_keys.zig | 15 +++++++++++- src/input/key_encode.zig | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/input/function_keys.zig b/src/input/function_keys.zig index ac7f05d65..5390e2f63 100644 --- a/src/input/function_keys.zig +++ b/src/input/function_keys.zig @@ -89,7 +89,7 @@ pub const keys = keys: { result.set(.page_up, pcStyle("\x1b[5;{}~") ++ .{Entry{ .sequence = "\x1B[5~" }}); result.set(.page_down, pcStyle("\x1b[6;{}~") ++ .{Entry{ .sequence = "\x1B[6~" }}); - // Function Keys. todo: f13-f35 but we need to add to input.Key + // Function Keys. todo: f26-f35 but we need to add to input.Key result.set(.f1, pcStyle("\x1b[1;{}P") ++ .{Entry{ .sequence = "\x1BOP" }}); result.set(.f2, pcStyle("\x1b[1;{}Q") ++ .{Entry{ .sequence = "\x1BOQ" }}); result.set(.f3, pcStyle("\x1b[13;{}~") ++ .{Entry{ .sequence = "\x1BOR" }}); @@ -102,6 +102,19 @@ pub const keys = keys: { result.set(.f10, pcStyle("\x1b[21;{}~") ++ .{Entry{ .sequence = "\x1B[21~" }}); result.set(.f11, pcStyle("\x1b[23;{}~") ++ .{Entry{ .sequence = "\x1B[23~" }}); result.set(.f12, pcStyle("\x1b[24;{}~") ++ .{Entry{ .sequence = "\x1B[24~" }}); + result.set(.f13, pcStyle("\x1b[25;{}~") ++ .{Entry{ .sequence = "\x1B[25~" }}); + result.set(.f14, pcStyle("\x1b[26;{}~") ++ .{Entry{ .sequence = "\x1B[26~" }}); + result.set(.f15, pcStyle("\x1b[28;{}~") ++ .{Entry{ .sequence = "\x1B[28~" }}); + result.set(.f16, pcStyle("\x1b[29;{}~") ++ .{Entry{ .sequence = "\x1B[29~" }}); + result.set(.f17, pcStyle("\x1b[31;{}~") ++ .{Entry{ .sequence = "\x1B[31~" }}); + result.set(.f18, pcStyle("\x1b[32;{}~") ++ .{Entry{ .sequence = "\x1B[32~" }}); + result.set(.f19, pcStyle("\x1b[33;{}~") ++ .{Entry{ .sequence = "\x1B[33~" }}); + result.set(.f20, pcStyle("\x1b[34;{}~") ++ .{Entry{ .sequence = "\x1B[34~" }}); + result.set(.f21, pcStyle("\x1b[42;{}~") ++ .{Entry{ .sequence = "\x1B[42~" }}); + result.set(.f22, pcStyle("\x1b[43;{}~") ++ .{Entry{ .sequence = "\x1B[43~" }}); + result.set(.f23, pcStyle("\x1b[44;{}~") ++ .{Entry{ .sequence = "\x1B[44~" }}); + result.set(.f24, pcStyle("\x1b[45;{}~") ++ .{Entry{ .sequence = "\x1B[45~" }}); + result.set(.f25, pcStyle("\x1b[46;{}~") ++ .{Entry{ .sequence = "\x1B[46~" }}); // Keypad keys result.set(.numpad_0, kpKeys("p", "0")); diff --git a/src/input/key_encode.zig b/src/input/key_encode.zig index 0f45c8184..96eb6dec2 100644 --- a/src/input/key_encode.zig +++ b/src/input/key_encode.zig @@ -2510,6 +2510,54 @@ test "legacy: f1" { } } +test "legacy: f13 through f25" { + const Case = struct { key: key.Key, code: u8 }; + const cases = [_]Case{ + .{ .key = .f13, .code = 25 }, + .{ .key = .f14, .code = 26 }, + .{ .key = .f15, .code = 28 }, + .{ .key = .f16, .code = 29 }, + .{ .key = .f17, .code = 31 }, + .{ .key = .f18, .code = 32 }, + .{ .key = .f19, .code = 33 }, + .{ .key = .f20, .code = 34 }, + .{ .key = .f21, .code = 42 }, + .{ .key = .f22, .code = 43 }, + .{ .key = .f23, .code = 44 }, + .{ .key = .f24, .code = 45 }, + .{ .key = .f25, .code = 46 }, + }; + + var buf: [128]u8 = undefined; + var expected_buf: [32]u8 = undefined; + for (cases) |case| { + { + var writer: std.Io.Writer = .fixed(&buf); + try legacy(&writer, .{ .key = case.key }, .{}); + const expected = try std.fmt.bufPrint( + &expected_buf, + "\x1b[{}~", + .{case.code}, + ); + try testing.expectEqualStrings(expected, writer.buffered()); + } + + { + var writer: std.Io.Writer = .fixed(&buf); + try legacy(&writer, .{ + .key = case.key, + .mods = .{ .ctrl = true }, + }, .{ .modify_other_keys_state_2 = true }); + const expected = try std.fmt.bufPrint( + &expected_buf, + "\x1b[{};5~", + .{case.code}, + ); + try testing.expectEqualStrings(expected, writer.buffered()); + } + } +} + test "legacy: left_shift+tab" { var buf: [128]u8 = undefined; var writer: std.Io.Writer = .fixed(&buf);