summaryrefslogtreecommitdiff
path: root/test/hxkeys.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 07:44:55 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit0db7861d9da09e059fa1b9e40fff5cd52add27f2 (patch)
tree6e95dfa36e07b3234b1d5cdb990b11f95c184a3f /test/hxkeys.zig
parentd3742ddf2b3a85eb3935cb35e958fa27f1293a6b (diff)
parentdee94c740bdaea61ff35b4e0a7f1d2815c9ee441 (diff)
downloadpardes-0db7861d9da09e059fa1b9e40fff5cd52add27f2.tar.gz
pardes-0db7861d9da09e059fa1b9e40fff5cd52add27f2.zip
integration: the text pane a library (pardes-editor), with the GPU move, the terminal, the plumber and the diff work
A merge of pardes-next (wmrtztwl) and editor-lib (rlumrxuq), no conflicts. Gated against the baseline of the integration line (.scratch/sketch/gpu/mbase): the merge with the library before its follow-up, in full: frame corpus 77/77 identical in Debug and in ReleaseFast, the gated window -0.019% instructions (threshold 0.5%), unit-test on gui 1584/1592 with no failure the baseline has not; this merge: corpus 77/77 in Debug, unit-test on gui 1584/1592, on tui core-test 811/950 (139 skipped), shell-test 990/993, lib-test, hxdiff 658, parity 738, hxgolf 124, hxlib 538 and its parity 618, all 0 mismatches, replicas pass. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/hxkeys.zig')
-rw-r--r--test/hxkeys.zig80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/hxkeys.zig b/test/hxkeys.zig
new file mode 100644
index 00000000..c94e5900
--- /dev/null
+++ b/test/hxkeys.zig
@@ -0,0 +1,80 @@
+//! helix's key notation as hxdiff's cases spell it (test/hxcases): the
+//! next key of `keys` from `i.*`, null at the end; printables verbatim,
+//! `<...>` specials and modifiers. The core's harness (hxdiff.zig) and the
+//! library's (hxlib.zig) read the cases through it.
+const std = @import("std");
+
+pub fn next(comptime Key: type, keys: []const u8, i: *usize) !?Key {
+ if (i.* >= keys.len) return null;
+ var key: Key = .{ .cp = 0 };
+ if (keys[i.*] == '<') {
+ const close = std.mem.indexOfScalarPos(u8, keys, i.*, '>') orelse
+ return error.UnterminatedKey;
+ var name = keys[i.* + 1 .. close];
+ i.* = close + 1;
+ while (true) {
+ if (std.mem.startsWith(u8, name, "C-")) {
+ key.ctrl = true;
+ name = name[2..];
+ } else if (std.mem.startsWith(u8, name, "A-")) {
+ key.alt = true;
+ name = name[2..];
+ } else if (std.mem.startsWith(u8, name, "S-")) {
+ key.shift = true;
+ name = name[2..];
+ } else break;
+ }
+ if (name.len == 1 or (name.len > 1 and name.len <= 4 and name[0] >= 0x80)) {
+ key.cp = std.unicode.utf8Decode(name) catch return error.InvalidKey;
+ if (!key.ctrl and !key.alt) key.text = name;
+ } else if (std.mem.eql(u8, name, "esc")) {
+ key.cp = Key.escape;
+ } else if (std.mem.eql(u8, name, "ret")) {
+ key.cp = Key.enter;
+ } else if (std.mem.eql(u8, name, "tab")) {
+ key.cp = Key.tab;
+ } else if (std.mem.eql(u8, name, "space")) {
+ key.cp = ' ';
+ if (!key.ctrl and !key.alt) key.text = " ";
+ } else if (std.mem.eql(u8, name, "backspace")) {
+ key.cp = Key.backspace;
+ } else if (std.mem.eql(u8, name, "del")) {
+ key.cp = Key.delete;
+ } else if (std.mem.eql(u8, name, "lt")) {
+ key.cp = '<';
+ if (!key.ctrl and !key.alt) key.text = "<";
+ } else if (std.mem.eql(u8, name, "gt")) {
+ key.cp = '>';
+ if (!key.ctrl and !key.alt) key.text = ">";
+ } else if (std.mem.eql(u8, name, "minus")) {
+ // helix spells Alt-'-' this way: a bare `-` after a modifier
+ // is a parse error in its own macro notation
+ key.cp = '-';
+ if (!key.ctrl and !key.alt) key.text = "-";
+ } else if (std.mem.eql(u8, name, "up")) {
+ key.cp = Key.up;
+ } else if (std.mem.eql(u8, name, "down")) {
+ key.cp = Key.down;
+ } else if (std.mem.eql(u8, name, "left")) {
+ key.cp = Key.left;
+ } else if (std.mem.eql(u8, name, "right")) {
+ key.cp = Key.right;
+ } else if (std.mem.eql(u8, name, "home")) {
+ key.cp = Key.home;
+ } else if (std.mem.eql(u8, name, "end")) {
+ key.cp = Key.end;
+ } else if (std.mem.eql(u8, name, "pageup")) {
+ key.cp = Key.page_up;
+ } else if (std.mem.eql(u8, name, "pagedown")) {
+ key.cp = Key.page_down;
+ } else return error.UnknownKey;
+ } else {
+ const len = std.unicode.utf8ByteSequenceLength(keys[i.*]) catch return error.InvalidKey;
+ if (len > keys.len - i.*) return error.InvalidKey;
+ const text = keys[i.*..][0..len];
+ key.cp = std.unicode.utf8Decode(text) catch return error.InvalidKey;
+ key.text = text;
+ i.* += len;
+ }
+ return key;
+}