parse: ground parser complete
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
d22b2a89f3
commit
27548f7f9d
1 changed files with 22 additions and 22 deletions
44
src/Tty.zig
44
src/Tty.zig
|
@ -74,7 +74,7 @@ pub fn run(
|
||||||
ss3,
|
ss3,
|
||||||
};
|
};
|
||||||
|
|
||||||
const state: State = .ground;
|
var state: State = .ground;
|
||||||
|
|
||||||
// Set up fds for polling
|
// Set up fds for polling
|
||||||
var pollfds: [2]std.os.pollfd = .{
|
var pollfds: [2]std.os.pollfd = .{
|
||||||
|
@ -97,28 +97,28 @@ pub fn run(
|
||||||
const b = buf[i];
|
const b = buf[i];
|
||||||
switch (state) {
|
switch (state) {
|
||||||
.ground => {
|
.ground => {
|
||||||
switch (b) {
|
const key: ?Key = switch (b) {
|
||||||
0x00 => { // ctrl+@
|
0x00 => Key{ .codepoint = '@', .mods = .{ .ctrl = true } },
|
||||||
const event = Key{
|
0x01...0x1A => Key{ .codepoint = b + 0x60, .mods = .{ .ctrl = true } },
|
||||||
.codepoint = '@',
|
0x1B => escape: {
|
||||||
.mods = .{ .ctrl = true },
|
// NOTE: This could be an errant escape at the end
|
||||||
};
|
// of a large read. That is _incredibly_ unlikely
|
||||||
app.postEvent(.{ .key_press = event });
|
// given the size of read inputs and our read buffer
|
||||||
|
if (i == (n - 1)) {
|
||||||
|
const event = Key{
|
||||||
|
.codepoint = Key.escape,
|
||||||
|
};
|
||||||
|
break :escape event;
|
||||||
|
}
|
||||||
|
state = .escape;
|
||||||
|
break :escape null;
|
||||||
},
|
},
|
||||||
0x01...0x1A => { // ctrl+[a-z]
|
0x20...0x7E => Key{ .codepoint = b },
|
||||||
const event = Key{
|
0x7F => Key{ .codepoint = Key.backspace },
|
||||||
.codepoint = b + 0x60, // turn it lowercase
|
else => Key{ .codepoint = b },
|
||||||
.mods = .{ .ctrl = true },
|
};
|
||||||
};
|
if (key) |k| {
|
||||||
app.postEvent(.{ .key_press = event });
|
app.postEvent(.{ .key_press = k });
|
||||||
},
|
|
||||||
0x20...0x7E => { // ascii
|
|
||||||
const event = Key{
|
|
||||||
.codepoint = @intCast(b),
|
|
||||||
};
|
|
||||||
app.postEvent(.{ .key_press = event });
|
|
||||||
},
|
|
||||||
else => {},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
|
|
Loading…
Reference in a new issue