From 542e6677e23e277ce39edb3e96d729e9adca99d0 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 19:29:06 -0300 Subject: split pardes.zig by noun, keys: the keyboard leaves the session for src/keys.zig, free functions on it as mouse.zig is the mouse: handleKey, leaderKey, replayKeys, cycleMode, toggleTty, questionChoices and answerQuestion; their callers name keys (builtins.zig, ninep/ctl.zig, normal.zig, whose own `keys` are the replayed keys, so it imports the file as keyboard; update calls keys.handleKey); comments citing Pardes.handleKey and Pardes.answerQuestion cite keys; tests moved with them, by name: Esc back into a tty leaves its view at the prompt; Del from a key asks which neighbour takes the rows; nothing else asks; raw tty Esc backs out and Shift-Esc is the program's Esc; with ProgramEsc raw tty Escape only leaves at a shell prompt; the Del question shows only once its delay is up: a quick SPC d j never sees it; raw tty Ctrl-B switches to editor mode without sending child input; raw tty forwards Ctrl letters and former global shortcuts to the child; s in a header selects in the header's own text; a pure move, no field touched, a dump and the wire as they were; gates on tui: core-test 960/960, behaviour-test 238/238 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/ctl.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ninep/ctl.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index ec870253..3393c851 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -17,6 +17,7 @@ const builtins = @import("../builtins.zig"); const exec_line = @import("../exec.zig"); const tree = @import("tree.zig"); const pane_files = @import("pane.zig"); +const keys = @import("../keys.zig"); const Pardes = pardes.Pardes; const Pane = pardes.Pane; @@ -1103,7 +1104,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { } else if (std.mem.eql(u8, line, "answer")) { // With a question up, what it offers. var offered: [64]u8 = undefined; - if (p.questionChoices(p.paneBySerial(serial).?, &offered)) |choices| + if (keys.questionChoices(p, p.paneBySerial(serial).?, &offered)) |choices| return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices}) catch "answer takes a choice or -"); return tree.failText(req.tag, E.INVAL, "answer takes a choice or -"); } else if (std.mem.startsWith(u8, line, "answer ") and p.panes[p.paneBySerial(serial).?].?.prompt == .save) { @@ -1121,7 +1122,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { const choice = std.mem.trim(u8, line["answer ".len..], " "); const id = p.paneBySerial(serial).?; var offered: [64]u8 = undefined; - const choices = p.questionChoices(id, &offered) orelse return refuse(p, req, "no question asked", line); + const choices = keys.questionChoices(p, id, &offered) orelse return refuse(p, req, "no question asked", line); // Only a choice the question offers answers it; anything // else leaves it standing, and says what it takes. if (!std.mem.eql(u8, choice, "-") and (choice.len != 1 or std.mem.indexOfScalar(u8, choices, choice[0]) == null)) { @@ -1129,7 +1130,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { // The choice refused is what is quoted: `answer takes a b or - "z"`. return refuseQuoting(p, req, std.fmt.bufPrint(&why, "answer takes {s} or -", .{choices}) catch "answer takes a choice or -", choice, ""); } - if (apply) _ = p.answerQuestion(id, if (choice[0] == '-') null else choice[0]); + if (apply) _ = keys.answerQuestion(p, id, if (choice[0] == '-') null else choice[0]); } else if (!apply) { if (checkBuiltin(p, req, line, .pane)) |refusal| return refusal; // Edit on a pane with no text is the refusal a data write -- cgit v1.3