summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig62
1 files changed, 14 insertions, 48 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index c3658df4..30ba8bf7 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -374,31 +374,18 @@ pub fn readResults(p: *Pardes, req: Req) Reply {
// ---- /status ----
-fn statusText(p: *Pardes, buf: []u8) []const u8 {
- var w = std.Io.Writer.fixed(buf);
+/// /status's text, in the step's scratch.
+pub fn statusText(p: *Pardes) []const u8 {
+ var w: std.Io.Writer.Allocating = .init(p.scratch.allocator());
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
const pid: u32 = if (comptime pardes.hosted) @intCast(std.c.getpid()) else 0;
- w.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count }) catch {};
+ w.writer.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count }) catch {};
// Whether the pointer is over this window: what a grip let go past
// another window's edge asks of every window, to find the one it was
// let go over (Handover.zig), where no window may know another's place.
- if (p.windowed) w.print("pointer {s}\n", .{if (p.pointer_inside) "in" else "out"}) catch {};
- return w.buffered();
-}
-
-pub const status_text_cap = 80 + pardes.version.len;
-
-pub fn statusLen(p: *Pardes) u64 {
- var buf: [status_text_cap]u8 = undefined;
- return statusText(p, &buf).len;
-}
-
-pub fn readStatus(p: *Pardes, req: Req) Reply {
- var buf: [status_text_cap]u8 = undefined;
- const out = p.fs.stage(p.gpa);
- out.appendSlice(p.gpa, statusText(p, &buf)) catch return Reply.fail(req.tag, E.NOMEM);
- return tree.stagedReply(p, req);
+ if (p.windowed) w.writer.print("pointer {s}\n", .{if (p.pointer_inside) "in" else "out"}) catch {};
+ return w.written();
}
// ---- /pane/<n>/ctl ----
@@ -656,18 +643,11 @@ fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, cap
});
}
-pub fn rootLen(p: *Pardes) u64 {
- var buf: [256]u8 = undefined;
- var counting: std.Io.Writer.Discarding = .init(&buf);
- writeSettings(p, &counting.writer) catch return 0;
- return counting.fullCount();
-}
-
-pub fn readRoot(p: *Pardes, req: Req) Reply {
+/// The root ctl's text (`writeSettings`), in the step's scratch.
+pub fn settingsText(p: *Pardes) ![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- writeSettings(p, &text.writer) catch return Reply.fail(req.tag, E.NOMEM);
- p.fs.stage(p.gpa).appendSlice(p.gpa, text.written()) catch return Reply.fail(req.tag, E.NOMEM);
- return tree.stagedReply(p, req);
+ try writeSettings(p, &text.writer);
+ return text.written();
}
/// /pager, `pardes -`'s: the directory written (empty, or not absolute: the
@@ -919,18 +899,11 @@ fn writeCommands(p: *const Pardes, w: *std.Io.Writer) !void {
}
}
-pub fn commandsLen(p: *const Pardes) u64 {
- var buf: [256]u8 = undefined;
- var counting: std.Io.Writer.Discarding = .init(&buf);
- writeCommands(p, &counting.writer) catch return 0;
- return counting.fullCount();
-}
-
-pub fn readCommands(p: *Pardes, req: Req) Reply {
+/// /commands' text (`writeCommands`), in the step's scratch.
+pub fn commandsText(p: *Pardes) ![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- writeCommands(p, &text.writer) catch return Reply.fail(req.tag, E.NOMEM);
- p.fs.stage(p.gpa).appendSlice(p.gpa, text.written()) catch return Reply.fail(req.tag, E.NOMEM);
- return tree.stagedReply(p, req);
+ try writeCommands(p, &text.writer);
+ return text.written();
}
// ---- /focus ----
@@ -1062,13 +1035,6 @@ pub fn writeMousein(p: *Pardes, req: Req) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
-pub fn readPane(p: *Pardes, req: Req, pane: *Pane) Reply {
- var buf: [pane_text_cap]u8 = undefined;
- const out = p.fs.stage(p.gpa);
- out.appendSlice(p.gpa, paneText(p, pane, &buf)) catch return Reply.fail(req.tag, E.NOMEM);
- return tree.stagedReply(p, req);
-}
-
/// `get` reloads the buffer from the name it carries, wherever that name
/// resolves. Any other line is a builtin that acts on a pane (`Del`,
/// `Save f`), run at this one; a session's builtin is the root ctl's.