parse: ground parser complete

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-01-18 20:30:42 -06:00
parent d22b2a89f3
commit 27548f7f9d

View file

@ -74,7 +74,7 @@ pub fn run(
ss3,
};
const state: State = .ground;
var state: State = .ground;
// Set up fds for polling
var pollfds: [2]std.os.pollfd = .{
@ -97,28 +97,28 @@ pub fn run(
const b = buf[i];
switch (state) {
.ground => {
switch (b) {
0x00 => { // ctrl+@
const key: ?Key = switch (b) {
0x00 => Key{ .codepoint = '@', .mods = .{ .ctrl = true } },
0x01...0x1A => Key{ .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
// given the size of read inputs and our read buffer
if (i == (n - 1)) {
const event = Key{
.codepoint = '@',
.mods = .{ .ctrl = true },
.codepoint = Key.escape,
};
app.postEvent(.{ .key_press = event });
break :escape event;
}
state = .escape;
break :escape null;
},
0x01...0x1A => { // ctrl+[a-z]
const event = Key{
.codepoint = b + 0x60, // turn it lowercase
.mods = .{ .ctrl = true },
0x20...0x7E => Key{ .codepoint = b },
0x7F => Key{ .codepoint = Key.backspace },
else => Key{ .codepoint = b },
};
app.postEvent(.{ .key_press = event });
},
0x20...0x7E => { // ascii
const event = Key{
.codepoint = @intCast(b),
};
app.postEvent(.{ .key_press = event });
},
else => {},
if (key) |k| {
app.postEvent(.{ .key_press = k });
}
},
else => {},