diff --git a/examples/text_input.zig b/examples/text_input.zig index aa6a825..86f4a71 100644 --- a/examples/text_input.zig +++ b/examples/text_input.zig @@ -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); }, diff --git a/src/Parser.zig b/src/Parser.zig index 7a5720a..8e9f79c 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -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 = .{};