From 04f6117cfe917010b93bb990ec43f1133da5af34 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 23 Jan 2024 21:30:09 -0600 Subject: [PATCH] vaxis: enable da1 parsing, use futex timeout to return from query Now that DA1 parsing is done, block the queryTerminal function until the DA1 response is received, or a 1 second timeout elapses. With this functionality, move certain events into Vaxis's realm of handling: IE enabling kitty keyboard, unicode mode, etc Signed-off-by: Tim Culverhouse --- examples/text_input.zig | 4 ---- src/Parser.zig | 11 +++++++++++ src/Tty.zig | 15 ++++++--------- src/ctlseqs.zig | 3 +++ src/event.zig | 4 ++-- src/main.zig | 1 - src/vaxis.zig | 26 +++++++++++++++++++++++++- 7 files changed, 47 insertions(+), 17 deletions(-) diff --git a/examples/text_input.zig b/examples/text_input.zig index 3fe7c9b..aa6a825 100644 --- a/examples/text_input.zig +++ b/examples/text_input.zig @@ -61,8 +61,6 @@ pub fn main() !void { .winsize => |ws| { try vx.resize(alloc, ws); }, - .cap_rgb => continue, - .cap_kitty_keyboard => try vx.enableKittyKeyboard(.{}), else => {}, } @@ -98,7 +96,5 @@ const Event = union(enum) { key_press: vaxis.Key, winsize: vaxis.Winsize, focus_in, - cap_rgb, - cap_kitty_keyboard, foo: u8, }; diff --git a/src/Parser.zig b/src/Parser.zig index a6a3751..7a5720a 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -357,6 +357,17 @@ pub fn parse(self: *Parser, input: []const u8) !Result { log.warn("unhandled csi: CSI {s}", .{input[start + 1 .. i + 1]}); return .{ .event = null, .n = i + 1 }; }, + 'c' => { // DA1 response + const priv = seq.private_indicator orelse { + log.warn("unhandled csi: CSI {s}", .{input[start + 1 .. i + 1]}); + return .{ .event = null, .n = i + 1 }; + }; + if (priv != '?') { + log.warn("unhandled csi: CSI {s}", .{input[start + 1 .. i + 1]}); + return .{ .event = null, .n = i + 1 }; + } + return .{ .event = .cap_da1, .n = i + 1 }; + }, else => { log.warn("unhandled csi: CSI {s}", .{input[start + 1 .. i + 1]}); return .{ diff --git a/src/Tty.zig b/src/Tty.zig index 0e2baa6..44fd86f 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -178,19 +178,16 @@ pub fn run( } }, .cap_kitty_keyboard => { - if (@hasField(EventType, "cap_kitty_keyboard")) { - vx.postEvent(.cap_kitty_keyboard); - } + vx.caps.kitty_keyboard = true; }, .cap_rgb => { - if (@hasField(EventType, "cap_rgb")) { - vx.postEvent(.cap_rgb); - } + vx.caps.rgb = true; }, .cap_unicode => { - if (@hasField(EventType, "cap_unicode")) { - vx.postEvent(.cap_unicode); - } + vx.caps.unicode = true; + }, + .cap_da1 => { + std.Thread.Futex.wake(&vx.query_futex, 10); }, } } diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index 05d0f81..faf2b7d 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -14,6 +14,9 @@ pub const sixel_geometry_query = "\x1b[?2;1;0S"; pub const sync_set = "\x1b[?2026h"; pub const sync_reset = "\x1b[?2026l"; +pub const unicode_set = "\x1b[?2027h"; +pub const unicode_reset = "\x1b[?2027l"; + // Key encoding pub const csi_u_push = "\x1b[>{d}u"; pub const csi_u_pop = "\x1b[