input: correct xterm encoding for modified F1-F4

Fixes #499
This commit is contained in:
Mitchell Hashimoto
2023-09-20 14:33:55 -07:00
parent 59267c4c4d
commit 9ad27924a6
2 changed files with 50 additions and 4 deletions

View File

@ -1106,6 +1106,52 @@ test "legacy: keypad enter" {
try testing.expectEqualStrings("\r", actual); try testing.expectEqualStrings("\r", actual);
} }
test "legacy: f1" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .f1,
.mods = .{ .ctrl = true },
.consumed_mods = .{},
},
};
// F1
{
enc.event.key = .f1;
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[1;5P", actual);
}
// F2
{
enc.event.key = .f2;
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[1;5Q", actual);
}
// F3
{
enc.event.key = .f3;
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[1;5R", actual);
}
// F4
{
enc.event.key = .f4;
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[1;5S", actual);
}
// F5 uses new encoding
{
enc.event.key = .f5;
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[15;5~", actual);
}
}
test "ctrlseq: normal ctrl c" { test "ctrlseq: normal ctrl c" {
const seq = ctrlSeq(.c, .{ .ctrl = true }); const seq = ctrlSeq(.c, .{ .ctrl = true });
try testing.expectEqual(@as(u8, 0x03), seq.?); try testing.expectEqual(@as(u8, 0x03), seq.?);

View File

@ -87,10 +87,10 @@ pub const keys = keys: {
result.set(.page_down, pcStyle("\x1b[6;{}~") ++ .{.{ .sequence = "\x1B[6~" }}); result.set(.page_down, pcStyle("\x1b[6;{}~") ++ .{.{ .sequence = "\x1B[6~" }});
// Function Keys. todo: f13-f35 but we need to add to input.Key // Function Keys. todo: f13-f35 but we need to add to input.Key
result.set(.f1, pcStyle("\x1b[11;{}~") ++ .{.{ .sequence = "\x1BOP" }}); result.set(.f1, pcStyle("\x1b[1;{}P") ++ .{.{ .sequence = "\x1BOP" }});
result.set(.f2, pcStyle("\x1b[12;{}~") ++ .{.{ .sequence = "\x1BOQ" }}); result.set(.f2, pcStyle("\x1b[1;{}Q") ++ .{.{ .sequence = "\x1BOQ" }});
result.set(.f3, pcStyle("\x1b[13;{}~") ++ .{.{ .sequence = "\x1BOR" }}); result.set(.f3, pcStyle("\x1b[1;{}R") ++ .{.{ .sequence = "\x1BOR" }});
result.set(.f4, pcStyle("\x1b[14;{}~") ++ .{.{ .sequence = "\x1BOS" }}); result.set(.f4, pcStyle("\x1b[1;{}S") ++ .{.{ .sequence = "\x1BOS" }});
result.set(.f5, pcStyle("\x1b[15;{}~") ++ .{.{ .sequence = "\x1B[15~" }}); result.set(.f5, pcStyle("\x1b[15;{}~") ++ .{.{ .sequence = "\x1B[15~" }});
result.set(.f6, pcStyle("\x1b[17;{}~") ++ .{.{ .sequence = "\x1B[17~" }}); result.set(.f6, pcStyle("\x1b[17;{}~") ++ .{.{ .sequence = "\x1B[17~" }});
result.set(.f7, pcStyle("\x1b[18;{}~") ++ .{.{ .sequence = "\x1B[18~" }}); result.set(.f7, pcStyle("\x1b[18;{}~") ++ .{.{ .sequence = "\x1B[18~" }});