diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 21:44:44 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | 714da820136ac89d6a79ed0141e7325829ab8204 (patch) | |
| tree | bb9126953ddabb1321e04527c128bbf4a1f7cff0 /src/esp32p4.zig | |
| parent | 45609211f5047b5aec9964807cd5c98242cc70d7 (diff) | |
| download | pardes-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/esp32p4.zig')
| -rw-r--r-- | src/esp32p4.zig | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/src/esp32p4.zig b/src/esp32p4.zig index b7725b81..4e1fe036 100644 --- a/src/esp32p4.zig +++ b/src/esp32p4.zig @@ -32,6 +32,7 @@ const std = @import("std"); const builtin = @import("builtin"); const pardes = @import("pardes.zig"); const vaxis = @import("vaxis"); +const vaxis_input = @import("vaxis_input.zig"); // ------------------------------------------------------------------ what a freestanding root owes // @@ -394,7 +395,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void { // text at all, so a line break inside a paste arrives as a bare CR (Key.enter) or, from // a terminal that does not translate them, as ctrl+j. const text = key.text orelse ""; - const cp = mapKey(effCp(key)); + const cp = vaxis_input.mapKey(vaxis_input.effCp(key)); const bytes: []const u8 = if (text.len > 0) text else if (cp == pardes.Key.tab) @@ -406,7 +407,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void { if (bytes.len > 0) paste_buf.appendSlice(gpa(), bytes) catch {}; } else { c.update(.{ .key = .{ - .cp = mapKey(effCp(key)), + .cp = vaxis_input.mapKey(vaxis_input.effCp(key)), .text = key.text orelse "", .ctrl = key.mods.ctrl, .alt = key.mods.alt, @@ -529,35 +530,6 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void { } } -/// The effective codepoint the way vaxis's own `Key.matches` sees it: a single-character `text` -/// wins, because the terminal has already resolved shift; otherwise the shifted codepoint. -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; -} - -/// vaxis functional-key codepoints -> core constants. The ASCII ones already coincide, so -/// enter/tab/escape/backspace pass straight through. -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, - }; -} export fn pardes_esp32p4_tick(now_ms: u64) callconv(.c) void { const c = core orelse return; last_now_ms = now_ms; |
