summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 21:44:44 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:17 -0300
commit714da820136ac89d6a79ed0141e7325829ab8204 (patch)
treebb9126953ddabb1321e04527c128bbf4a1f7cff0 /src/gui/gui.zig
parent45609211f5047b5aec9964807cd5c98242cc70d7 (diff)
downloadpardes-714da820136ac89d6a79ed0141e7325829ab8204.tar.gz
pardes-714da820136ac89d6a79ed0141e7325829ab8204.zip
F1-F25, Insert and the keypad reach a GUI's terminal panes: one vaxis key map, vaxis_input.zig, for the tty, the gui and the board
The vaxis-to-Event key mapping was copied in tty.zig, gui.zig and esp32p4.zig, and the copies had drifted: the gui's (its stdin feed, which test windows and a gui started in a terminal read) had 9 arms against the tty's 26, without the function keys, Insert or the keypad, so they reached a terminal pane as private-use codepoints. vaxis_input.zig holds effCp, mapKey and keyEvent once; the gui posts through postKey, and a test runs F5, Insert and the keypad's Up through it into a terminal pane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index df565b94..8b100cd8 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -6,6 +6,7 @@ const libc = std.c;
const vaxis = @import("vaxis"); // test modes only: the stdin escape-seq parser
const ghostty_vt = @import("ghostty-vt"); // 256-color palette for .index cells
const pardes = @import("../pardes.zig");
+const vaxis_input = @import("../vaxis_input.zig");
const dump = @import("../dump.zig");
const config = @import("../config.zig");
const look = @import("../look.zig");
@@ -3225,15 +3226,7 @@ const StdinFeed = struct {
const event = result.event orelse continue;
switch (event) {
.key_press => |key| {
- var text: []const u8 = "";
- if (key.text) |t| text = f.cache.put(t);
- in.post(.{ .key = .{
- .cp = mapKey(effCp(key)),
- .text = text,
- .ctrl = key.mods.ctrl,
- .alt = key.mods.alt,
- .shift = key.mods.shift,
- } });
+ postKey(in, key, if (key.text) |t| f.cache.put(t) else "");
out.n_events += 1;
},
.mouse => |m| {
@@ -3382,6 +3375,40 @@ fn dumpGrid(gpa: std.mem.Allocator, surface: *pardes.Surface) !void {
_ = host_io.writeFd(1, frame);
}
+/// A key parsed from the stdin a test window reads, posted as the tty
+/// posts one (vaxis_input): F-keys, Insert and the keypad included. `text`
+/// is the key's text as the feed keeps it.
+fn postKey(in: *Input, key: vaxis.Key, text: []const u8) void {
+ var ev = vaxis_input.keyEvent(key);
+ ev.key.text = text;
+ in.post(ev);
+}
+
+test "the GUI's stdin keys reach a terminal pane as the tty's do: F5, Insert and the keypad's Up" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true });
+ defer core.deinit();
+ core.panes[0].?.body.mode = .tty;
+ while (core.nextEffect()) |_| {}
+ var in: Input = .{ .core = core };
+ var parser: vaxis.Parser = .{};
+ var bytes: []const u8 = "\x1b[15~\x1b[2~\x1b[57419u";
+ while (bytes.len > 0) {
+ const result = try parser.parse(bytes, gpa);
+ bytes = bytes[result.n..];
+ if (result.event) |event| switch (event) {
+ .key_press => |key| postKey(&in, key, key.text orelse ""),
+ else => {},
+ };
+ }
+ var written: std.Io.Writer.Allocating = .init(gpa);
+ defer written.deinit();
+ while (core.nextEffect()) |effect| {
+ if (effect == .write) try written.writer.writeAll(effect.write.bytes.slice());
+ }
+ try std.testing.expectEqualStrings("\x1b[15~\x1b[2~\x1b[A", written.written());
+}
+
const Input = struct {
core: ?*pardes.Pardes = null,
client: ?*detached_client.Client = null,
@@ -10439,32 +10466,6 @@ fn miniGlyph(ch: u8) [5]u8 {
};
}
-fn effCp(key: vaxis.Key) u21 {
- if (key.text) |t| {
- const view = std.unicode.Utf8View.init(t) catch return key.codepoint;
- var it = view.iterator();
- if (it.nextCodepoint()) |cp| {
- if (it.nextCodepoint() == null) return cp;
- }
- }
- return key.shifted_codepoint orelse key.codepoint;
-}
-
-fn mapKey(cp: u21) u21 {
- return switch (cp) {
- vaxis.Key.up => pardes.Key.up,
- vaxis.Key.down => pardes.Key.down,
- vaxis.Key.left => pardes.Key.left,
- vaxis.Key.right => pardes.Key.right,
- vaxis.Key.home => pardes.Key.home,
- vaxis.Key.end => pardes.Key.end,
- vaxis.Key.page_up => pardes.Key.page_up,
- vaxis.Key.page_down => pardes.Key.page_down,
- vaxis.Key.delete => pardes.Key.delete,
- else => cp,
- };
-}
-
fn envU16(env: *std.process.Environ.Map, name: []const u8) ?u16 {
const raw = env.get(name) orelse return null;
return std.fmt.parseInt(u16, raw, 10) catch null;