summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:12:27 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:58 -0300
commit86b873a851820485c5720463195ff98466ddc315 (patch)
tree3236c904a30be8ce8a66622c9c04bd22ffb047ea
parentfe66ef6a44a38465c12e6a57c6d40af4d33ca7d9 (diff)
downloadpardes-86b873a851820485c5720463195ff98466ddc315.tar.gz
pardes-86b873a851820485c5720463195ff98466ddc315.zip
events: noteAction answers nothing, as all ten callers threw its bool away, and formats its record itself; noteFollow was noteAction at 0 0 0, so mouse.zig's two calls name noteAction; formatRecord, Action.char and Action.fromChar, one or two callers each, go
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/9p_io.zig2
-rw-r--r--src/mouse.zig6
-rw-r--r--src/ninep/ctl.zig2
-rw-r--r--src/ninep/events.zig78
4 files changed, 23 insertions, 65 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig
index 52352684..78a08275 100644
--- a/src/9p_io.zig
+++ b/src/9p_io.zig
@@ -1651,7 +1651,7 @@ test "a held read is answered when the log has news, and a flushed one spends no
try heldNow.count(p, 1);
pardes.turn.wake();
p.fs.origin = 'K';
- _ = pardes.ctlfs.events.noteAction(p, 0, .body_exec, 0, 4, 0, "held");
+ pardes.ctlfs.events.noteAction(p, 0, .body_exec, 0, 4, 0, "held");
pardes.turn.rest();
const clicked = try s.settle();
try testing.expectEqual(reused, clicked.tag);
diff --git a/src/mouse.zig b/src/mouse.zig
index cb218a36..02e3b6a5 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -1044,14 +1044,14 @@ pub fn reportRange(
} else if (chord_arg != null) flag |= ctlfs.events.flag_chorded;
// Taken whether or not this process's server has the reader: the
// session's said it has (a replica's has none).
- _ = ctlfs.events.noteAction(p, id, action, range.q0, range.q1, flag, text);
+ ctlfs.events.noteAction(p, id, action, range.q0, range.q1, flag, text);
// A chorded exec's argument follows as two records, its text and where
// it came from (`file:#q0,#q1`, empty when that is not known), as acme
// sends them (exec.c:182-188); the pane keeps it for the write-back.
if (chord_arg) |a| {
- ctlfs.events.noteFollow(p, id, action, a);
+ ctlfs.events.noteAction(p, id, action, 0, 0, 0, a);
var where: [512]u8 = undefined;
- ctlfs.events.noteFollow(p, id, action, exec.heldSelectionPlace(p, id, &where) orelse "");
+ ctlfs.events.noteAction(p, id, action, 0, 0, 0, exec.heldSelectionPlace(p, id, &where) orelse "");
const pf = &scripted.fs;
if (pf.chord_arg) |old| p.gpa.free(old);
pf.chord_arg = p.gpa.dupe(u8, a) catch null;
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index de4166cd..aad2675c 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -72,7 +72,7 @@ pub fn run(p: *Pardes, id: usize, exec: bool, text: []const u8, in_tag: bool) vo
(if (exec) .tag_exec else .tag_look)
else
(if (exec) .body_exec else .body_look);
- _ = pardes.ctlfs.events.noteAction(p, id, action, 0, 0, flag, text);
+ pardes.ctlfs.events.noteAction(p, id, action, 0, 0, flag, text);
return noteResult(p, context);
}
const before = Serials.snapshot(p);
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index e67deb1d..1a0e9a86 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -540,14 +540,6 @@ pub const Action = enum(u8) {
body_exec = 'X',
tag_exec = 'x',
- pub fn char(a: Action) u8 {
- return @backingInt(a);
- }
-
- pub fn fromChar(c: u8) ?Action {
- return std.enums.fromInt(Action, c);
- }
-
pub fn onTag(a: Action) bool {
return @backingInt(a) >= 'a';
}
@@ -557,27 +549,6 @@ pub const flag_builtin: u32 = 1;
pub const flag_filename: u32 = 4;
pub const flag_chorded: u32 = 8;
-pub fn formatRecord(
- buf: []u8,
- origin: u8,
- action: Action,
- q0: u32,
- q1: u32,
- flag: u32,
- text: []const u8,
-) []const u8 {
- const sent = if (text.len >= max_record_text) text[0..0] else text;
- return std.fmt.bufPrint(buf, "{c}{c}{d} {d} {d} {d} {s}\n", .{
- origin,
- action.char(),
- q0,
- q1,
- flag,
- sent.len,
- sent,
- }) catch buf[0..0];
-}
-
pub const Span = struct { at: u32, removed: u32, inserted: u32 };
pub fn diffSpan(old: []const u8, new: []const u8) Span {
@@ -607,7 +578,7 @@ pub fn noteReplace(p: *Pardes, id: usize, on_tag: bool, old: []const u8, new: []
if (pane.fs.readers == 0) return;
const span = diffSpan(old, new);
if (span.removed == 0 and span.inserted == 0) return;
- if (span.removed > 0) _ = noteAction(
+ if (span.removed > 0) noteAction(
p,
id,
if (on_tag) .tag_delete else .body_delete,
@@ -616,7 +587,7 @@ pub fn noteReplace(p: *Pardes, id: usize, on_tag: bool, old: []const u8, new: []
0,
"",
);
- if (span.inserted > 0) _ = noteAction(
+ if (span.inserted > 0) noteAction(
p,
id,
if (on_tag) .tag_insert else .body_insert,
@@ -627,31 +598,18 @@ pub fn noteReplace(p: *Pardes, id: usize, on_tag: bool, old: []const u8, new: []
);
}
-pub fn noteAction(
- p: *Pardes,
- id: usize,
- action: Action,
- q0: u32,
- q1: u32,
- flag: u32,
- text: []const u8,
-) bool {
- const pane = p.panes[id] orelse return false;
- if (pane.fs.readers == 0) return false;
- var buf: [max_record_text + 64]u8 = undefined;
- const record = formatRecord(&buf, p.fs.origin, action, q0, q1, flag, text);
- pane.fs.events.push(p.gpa, record);
- p.fs.news = true;
- return true;
-}
-
-/// A record that follows another with no place of its own, `<c>0 0 0 <n>
-/// <text>`: a chorded exec's argument and its location (acme exec.c:182).
-pub fn noteFollow(p: *Pardes, id: usize, action: Action, text: []const u8) void {
+/// Records `<origin><action><q0> <q1> <flag> <n> <text>` for a pane a
+/// script reads; a text of max_record_text and over is sent as none. One
+/// that follows another with no place of its own (a chorded exec's
+/// argument and its location, acme exec.c:182) is `<c>0 0 0 <n> <text>`.
+pub fn noteAction(p: *Pardes, id: usize, action: Action, q0: u32, q1: u32, flag: u32, text: []const u8) void {
const pane = p.panes[id] orelse return;
if (pane.fs.readers == 0) return;
+ const sent = if (text.len >= max_record_text) text[0..0] else text;
var buf: [max_record_text + 64]u8 = undefined;
- pane.fs.events.push(p.gpa, formatRecord(&buf, p.fs.origin, action, 0, 0, 0, text));
+ // unreachable: two characters, four u32s, the count and a sent text fit
+ const record = std.fmt.bufPrint(&buf, "{c}{c}{d} {d} {d} {d} {s}\n", .{ p.fs.origin, @backingInt(action), q0, q1, flag, sent.len, sent }) catch unreachable;
+ pane.fs.events.push(p.gpa, record);
p.fs.news = true;
}
@@ -682,7 +640,7 @@ const EventReader = struct {
if (i + 2 > er.data.len) return null;
const origin = er.data[i];
i += 1;
- const action = Action.fromChar(er.data[i]) orelse return null;
+ const action = std.enums.fromInt(Action, er.data[i]) orelse return null;
i += 1;
const q0 = scanNumber(er.data, &i, &er.overflow) orelse return null;
const q1 = scanNumber(er.data, &i, &er.overflow) orelse return null;
@@ -909,7 +867,7 @@ test "event records are acme's bytes, one per read, and .again when empty" {
const serial = serialOf(p);
const event = Node.of(serial, .event);
- _ = noteAction(p, 0, .body_exec, 1, 4, flag_builtin, "sg ");
+ noteAction(p, 0, .body_exec, 1, 4, flag_builtin, "sg ");
try testing.expect(p.panes[0].?.fs.events.empty());
const h = call(p, .{ .tag = 10, .op = .open, .node = event });
@@ -919,19 +877,19 @@ test "event records are acme's bytes, one per read, and .again when empty" {
try testing.expectEqual(Status.again, rd(p, event, 0, 4096).reply.status);
p.fs.origin = 'M';
- _ = noteAction(p, 0, .body_exec, 1, 4, flag_builtin, "ell");
- _ = noteAction(p, 0, .body_delete, 0, 3, 0, "");
+ noteAction(p, 0, .body_exec, 1, 4, flag_builtin, "ell");
+ noteAction(p, 0, .body_delete, 0, 3, 0, "");
try testing.expectEqualStrings("MX1 4 1 3 ell\n", rd(p, event, 0, 4096).bytes);
try testing.expectEqualStrings("MD0 3 0 0 \n", rd(p, event, 0, 4096).bytes);
try testing.expectEqual(Status.again, rd(p, event, 0, 4096).reply.status);
- _ = noteAction(p, 0, .body_look, 0, 3, flag_filename, "one");
+ noteAction(p, 0, .body_look, 0, 3, flag_filename, "one");
// A short read takes the record's front; the next, the rest.
try testing.expectEqualStrings("ML0 ", rd(p, event, 0, 4).bytes);
try testing.expectEqualStrings("3 4 3 one\n", rd(p, event, 0, 4096).bytes);
const big = &@as([max_record_text]u8, @splat('z'));
- _ = noteAction(p, 0, .body_exec, 0, max_record_text, 0, big);
+ noteAction(p, 0, .body_exec, 0, max_record_text, 0, big);
try testing.expectEqualStrings("MX0 256 0 0 \n", rd(p, event, 0, 4096).bytes);
_ = call(p, .{ .tag = 11, .op = .release, .node = event, .handle = h.reply.handle });
@@ -969,7 +927,7 @@ test "a write through the filesystem is reported once, attributed to the file it
try testing.expectEqualStrings("EI8 14 0 6 three\n\n", body_recs[0]);
for (body_recs[1..]) |r| {
try testing.expectEqual(@as(u8, 'E'), r[0]);
- try testing.expect(Action.fromChar(r[1]).?.onTag());
+ try testing.expect(std.enums.fromInt(Action, r[1]).?.onTag());
}
_ = wr(p, Node.of(serial, .addr), "1");