parser: parse 0x08 as backspace

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-01-24 06:43:34 -06:00
parent 1b83dfe652
commit b57342726f
2 changed files with 21 additions and 4 deletions

View file

@ -50,14 +50,15 @@ pub fn main() !void {
255 => 0,
else => color_idx + 1,
};
try text_input.update(.{ .key_press = key });
if (key.matches('c', .{ .ctrl = true })) {
break :outer;
}
if (key.matches('l', .{ .ctrl = true })) {
} else if (key.matches('l', .{ .ctrl = true })) {
vx.queueRefresh();
} else {
try text_input.update(.{ .key_press = key });
}
},
.winsize => |ws| {
try vx.resize(alloc, ws);
},

View file

@ -71,7 +71,10 @@ pub fn parse(self: *Parser, input: []const u8) !Result {
// ascii characters when we can
const key: Key = switch (b) {
0x00 => .{ .codepoint = '@', .mods = .{ .ctrl = true } },
0x01...0x1A => .{ .codepoint = b + 0x60, .mods = .{ .ctrl = true } },
0x08 => .{ .codepoint = Key.backspace },
0x01...0x07,
0x09...0x1A,
=> .{ .codepoint = b + 0x60, .mods = .{ .ctrl = true } },
0x1B => escape: {
// NOTE: This could be an errant escape at the end
// of a large read. That is _incredibly_ unlikely
@ -466,6 +469,19 @@ test "parse: single xterm keypress" {
try testing.expectEqual(expected_event, result.event);
}
test "parse: single xterm keypress backspace" {
const input = "\x08";
var parser: Parser = .{};
const result = try parser.parse(input);
const expected_key: Key = .{
.codepoint = Key.backspace,
};
const expected_event: Event = .{ .key_press = expected_key };
try testing.expectEqual(1, result.n);
try testing.expectEqual(expected_event, result.event);
}
test "parse: single xterm keypress with more buffer" {
const input = "ab";
var parser: Parser = .{};