terminfo: reset kbs back to ^?, clear high bit for encoding

This commit is contained in:
Mitchell Hashimoto
2024-04-21 09:52:18 -07:00
parent 542b416cf1
commit ae987c68e0
2 changed files with 15 additions and 3 deletions

View File

@ -101,8 +101,15 @@ pub fn xtgettcapMap(comptime self: Source) type {
// Replace '^' with the control char version of that char. // Replace '^' with the control char version of that char.
while (std.mem.indexOfScalar(u8, result, '^')) |idx| { while (std.mem.indexOfScalar(u8, result, '^')) |idx| {
if (idx > 0) @compileError("handle control-char in middle of string"); if (idx > 0) @compileError("handle control-char in middle of string");
const c = result[idx + 1]; const replacement = switch (result[idx + 1]) {
result = comptimeReplace(result, result[idx .. idx + 2], &.{c - 64}); '?' => 0x7F, // DEL, special cased from ncurses
else => |c| c - 64,
};
result = comptimeReplace(
result,
result[idx .. idx + 2],
&.{replacement},
);
} }
break :string result; break :string result;
}, },
@ -174,6 +181,7 @@ test "xtgettcap map" {
.capabilities = &.{ .capabilities = &.{
.{ .name = "am", .value = .{ .boolean = {} } }, .{ .name = "am", .value = .{ .boolean = {} } },
.{ .name = "colors", .value = .{ .numeric = 256 } }, .{ .name = "colors", .value = .{ .numeric = 256 } },
.{ .name = "kx", .value = .{ .string = "^?" } },
.{ .name = "kbs", .value = .{ .string = "^H" } }, .{ .name = "kbs", .value = .{ .string = "^H" } },
.{ .name = "kf1", .value = .{ .string = "\\EOP" } }, .{ .name = "kf1", .value = .{ .string = "\\EOP" } },
.{ .name = "Smulx", .value = .{ .string = "\\E[4:%p1%dm" } }, .{ .name = "Smulx", .value = .{ .string = "\\E[4:%p1%dm" } },
@ -185,6 +193,10 @@ test "xtgettcap map" {
"\x1bP1+r616D\x1b\\", "\x1bP1+r616D\x1b\\",
map.get(hexencode("am")).?, map.get(hexencode("am")).?,
); );
try testing.expectEqualStrings(
"\x1bP1+r6B78=7F\x1b\\",
map.get(hexencode("kx")).?,
);
try testing.expectEqualStrings( try testing.expectEqualStrings(
"\x1bP1+r6B6273=08\x1b\\", "\x1bP1+r6B6273=08\x1b\\",
map.get(hexencode("kbs")).?, map.get(hexencode("kbs")).?,

View File

@ -304,7 +304,7 @@ pub const ghostty: Source = .{
.{ .name = "kUP5", .value = .{ .string = "\\E[1;5A" } }, .{ .name = "kUP5", .value = .{ .string = "\\E[1;5A" } },
.{ .name = "kUP6", .value = .{ .string = "\\E[1;6A" } }, .{ .name = "kUP6", .value = .{ .string = "\\E[1;6A" } },
.{ .name = "kUP7", .value = .{ .string = "\\E[1;7A" } }, .{ .name = "kUP7", .value = .{ .string = "\\E[1;7A" } },
.{ .name = "kbs", .value = .{ .string = "^H" } }, .{ .name = "kbs", .value = .{ .string = "^?" } },
.{ .name = "kcbt", .value = .{ .string = "\\E[Z" } }, .{ .name = "kcbt", .value = .{ .string = "\\E[Z" } },
.{ .name = "kcub1", .value = .{ .string = "\\EOD" } }, .{ .name = "kcub1", .value = .{ .string = "\\EOD" } },
.{ .name = "kcud1", .value = .{ .string = "\\EOB" } }, .{ .name = "kcud1", .value = .{ .string = "\\EOB" } },