summaryrefslogtreecommitdiff
path: root/src/esp32p4.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/esp32p4.zig')
-rw-r--r--src/esp32p4.zig34
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;