input: encode F13 through F25

This commit is contained in:
Mitchell Hashimoto
2026-09-04 09:39:56 -07:00
parent 636a2f35b4
commit e7bdda9918
2 changed files with 62 additions and 1 deletions

View File

@@ -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"));

View File

@@ -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);