mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-19 18:26:13 +03:00
input: kitty encoding should only output unmodified utf8 if printable
This commit is contained in:
@ -105,7 +105,14 @@ fn kitty(
|
||||
if (self.event.utf8.len > 0 and
|
||||
binding_mods.empty() and
|
||||
self.event.action != .release)
|
||||
{
|
||||
plain_text: {
|
||||
// We only do this for printable characters. We should
|
||||
// inspect the real unicode codepoint properties here but
|
||||
// the real world issue is usually control characters.
|
||||
const view = try std.unicode.Utf8View.init(self.event.utf8);
|
||||
var it = view.iterator();
|
||||
while (it.nextCodepoint()) |cp| if (cp < 0x20) break :plain_text;
|
||||
|
||||
return try copyToBuf(buf, self.event.utf8);
|
||||
}
|
||||
}
|
||||
@ -839,6 +846,23 @@ test "kitty: matching unshifted codepoint" {
|
||||
try testing.expectEqualStrings("\x1b[65;2u", actual);
|
||||
}
|
||||
|
||||
// macOS generates utf8 text for arrow keys.
|
||||
test "kitty: up arrow with utf8" {
|
||||
var buf: [128]u8 = undefined;
|
||||
var enc: KeyEncoder = .{
|
||||
.event = .{
|
||||
.key = .up,
|
||||
.mods = .{},
|
||||
.utf8 = &.{30},
|
||||
},
|
||||
|
||||
.kitty_flags = .{ .disambiguate = true },
|
||||
};
|
||||
|
||||
const actual = try enc.kitty(&buf);
|
||||
try testing.expectEqualStrings("\x1b[A", actual);
|
||||
}
|
||||
|
||||
test "legacy: ctrl+alt+c" {
|
||||
var buf: [128]u8 = undefined;
|
||||
var enc: KeyEncoder = .{
|
||||
|
Reference in New Issue
Block a user