summaryrefslogtreecommitdiff
path: root/src/edit_cmd.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 14:39:47 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commite8e7ed956f3914a3790e980df0862b26c30bd611 (patch)
tree53d3247c594717f79745ad20c5dd23bf16ed59ea /src/edit_cmd.zig
parenta821fe82d8de3d407ebe104358b97719bd983727 (diff)
downloadpardes-e8e7ed956f3914a3790e980df0862b26c30bd611.tar.gz
pardes-e8e7ed956f3914a3790e980df0862b26c30bd611.zip
idioms #20, the bound in the type or the cut handled: of the 166 `catch unreachable` the pass kept, 64 stay where a reader checks the bound without arithmetic (an integer's digits, a declared field's size, and now the daemon's pid lists and the clock's two-digit fields written in their types), 69 texts print through Kind.Buf at their old size, 31 handle the failure once (a print into ename cut at its 320, paneText's line cut where its buffer fills, a log record or mouse report dropped rather than cut short, the question's letters that fit), Newcol's and pane/new's refusals are comptime strings, and dropUnsaved's too-long scratch name is null, not an empty sentinel
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/edit_cmd.zig')
-rw-r--r--src/edit_cmd.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig
index 0f10e136..b1239a84 100644
--- a/src/edit_cmd.zig
+++ b/src/edit_cmd.zig
@@ -176,9 +176,9 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
var world: World = .{ .p = p, .from = id, .arena = arena };
var why: sam.Why = .{};
- var text: [260]u8 = undefined;
+ var text: pardes.Kind.Buf(260) = .{};
const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet }, &why) catch |err| switch (err) {
- error.Edit => return p.reportFailure(id, std.fmt.bufPrint(&text, "Edit: {s}", .{why.text()}) catch unreachable), // why.text() is a slice of Why's [200]u8 buf; 6 more fit 260
+ error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})),
error.OutOfMemory => return p.reportError(id, "Edit", err),
};
// acme's Edit blocks the editor while its commands run; here the editor
@@ -194,7 +194,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
if (!touches) continue;
const q = p.panes[f.id] orelse continue;
for (running.res.files, 0..) |g, j| if (g.id == f.id and running.serials[j] == q.serial and changes(g))
- return p.reportFailure(id, std.fmt.bufPrint(&text, "Edit: busy: {s}: an Edit's commands are running on it", .{f.name[0..@min(f.name.len, 200)]}) catch unreachable); // 200 and 50 fit 260
+ return p.reportFailure(id, text.print("Edit: busy: {s}: an Edit's commands are running on it", .{f.name[0..@min(f.name.len, 200)]}));
}
}
if (res.undo != 0) {
@@ -323,14 +323,14 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
var out: std.Io.Writer.Allocating = .init(p.gpa);
defer out.deinit();
const w = &out.writer;
- var line: [256]u8 = undefined;
+ var line: pardes.Kind.Buf(256) = .{};
report: {
w.print("Edit: {c} {s}\n\n", .{ job.c, job.command }) catch break :report;
if (pd.res.jobs.len > 1) if (failure) |f| w.print("command {d} of {d}: ", .{ f.index + 1, pd.res.jobs.len }) catch break :report;
const why_at = out.written().len;
Pipe.writeFailure(w, failure) catch break :report;
const why = std.mem.sliceTo(out.written()[why_at..], '\n');
- const said = std.fmt.bufPrint(&line, "Edit: {c} {s}: {s}", .{ job.c, job.command[0..@min(job.command.len, 120)], why[0..@min(why.len, 120)] }) catch unreachable; // 240 and 10 fit 256
+ const said = line.print("Edit: {c} {s}: {s}", .{ job.c, job.command[0..@min(job.command.len, 120)], why });
const was = p.view().active;
_ = ninep_pane.appendErrors(p, at, out.written());
if (p.panes[was] != null) p.view().active = was;
@@ -344,13 +344,13 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
const res = pd.res;
const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.view().active) else p.view().active;
- var text: [320]u8 = undefined;
+ var text: pardes.Kind.Buf(320) = .{};
for (res.files, 0..) |f, i| {
if (f.ops.items.len == 0 and !f.close and !f.renamed and !f.moved and f.get == null) continue;
- const pane = p.panes[f.id] orelse return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 56 fit 320
- if (pane.serial != pd.serials[i]) return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 56 fit 320
+ const pane = p.panes[f.id] orelse return p.reportFailure(at, text.print("Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
+ if (pane.serial != pd.serials[i]) return p.reportFailure(at, text.print("Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
if ((f.ops.items.len > 0 or f.get != null) and pane.file.?.revision != pd.revisions[i])
- return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} changed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 57 fit 320
+ return p.reportFailure(at, text.print("Edit: {s} changed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
}
// e first, Get's way: read before anything is changed, so one that
// cannot be read changes nothing; its own undo step puts the old name
@@ -359,7 +359,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
const path = f.get orelse continue;
var failed: anyerror = error.Unexpected;
const errno = @import("ninep/ctl.zig").getFile(p, p.panes[f.id].?, path, &failed);
- if (errno != 0) return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" }) catch unreachable); // 256 and 24 fit 320
+ if (errno != 0) return p.reportFailure(at, text.print("Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" }));
}
// `w`'s bytes, written after this step, before anything else is. To
// its own file changed on disk since it was read, as Save is: refused
@@ -436,8 +436,8 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
if (p.panes[was] != null) p.view().active = was;
}
if (refused.written().len > 0) {
- var said: [320]u8 = undefined;
- p.reportFailure(at, std.fmt.bufPrint(&said, "Edit: w: {s} modified on disk since read (w again to overwrite)", .{refused.written()[0..@min(refused.written().len, 200)]}) catch unreachable); // 200 and 66 fit 320
+ var said: pardes.Kind.Buf(320) = .{};
+ p.reportFailure(at, said.print("Edit: w: {s} modified on disk since read (w again to overwrite)", .{refused.written()[0..@min(refused.written().len, 200)]}));
}
// D's panes last, each as Del closes one: an edited one is warned about
// once, and closes on the next.