From 66c4095e140694376fd07c3afa0fee721558bdb3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:38:29 -0300 Subject: ninep: one tree.window answers a read with the part of a text its offset and size ask for, where ten places (a frozen listing, a stream's replay, README, /screen, the sources, a PDF's or a terminal's body, a tag, a column's) windowed by hand; /status, the root ctl, /commands and /listeners are each one text in the step's scratch, read and counted from it, so the xLen and readX pairs (statusLen, rootLen, commandsLen, readStatus, readRoot, readCommands, readPane, readListeners) go; tree.read asks openOf once Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/screen.zig | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/ninep/screen.zig') diff --git a/src/ninep/screen.zig b/src/ninep/screen.zig index 22129546..c0251d80 100644 --- a/src/ninep/screen.zig +++ b/src/ninep/screen.zig @@ -49,32 +49,18 @@ pub fn readSnapshot(p: *Pardes, req: Req, pane: ?*Pane) Reply { const terminal = pane orelse return Reply.fail(req.tag, E.INVAL); snapshot.* = panes.terminal.screenTextAlloc(terminal, p.gpa) catch return Reply.fail(req.tag, E.NOMEM); } - const bytes = snapshot.*.?; - const off = @min(req.off, bytes.len); - const len = @min(bytes.len - off, req.size); - const out = p.fs.stage(p.gpa); - out.appendSlice(p.gpa, bytes[off..][0..len]) catch return Reply.fail(req.tag, E.NOMEM); - return .{ .tag = req.tag, .payload = .{ .staged = @intCast(len) } }; + return tree.window(p, req, snapshot.*.?); } -pub const listeners_cap = 512; - -pub fn listenersText(p: *Pardes, buf: []u8) []const u8 { - var text = std.Io.Writer.fixed(buf); - if (p.fs.socket_path.len != 0) - text.print("unix!{s}\n", .{p.fs.socket_path}) catch return text.buffered(); +/// /listeners' text, a dial a line, in the step's scratch. +pub fn listenersText(p: *Pardes) []const u8 { + var text: std.Io.Writer.Allocating = .init(p.scratch.allocator()); + if (p.fs.socket_path.len != 0) text.writer.print("unix!{s}\n", .{p.fs.socket_path}) catch {}; if (p.fs.tcp_address) |address| switch (address) { - .ip4 => |ip| text.print("tcp!{d}.{d}.{d}.{d}!{d}\n", .{ ip.bytes[0], ip.bytes[1], ip.bytes[2], ip.bytes[3], ip.port }) catch {}, - .ip6 => |ip| text.print("tcp!{f}!{d}\n", .{ std.Io.net.Ip6Address.Unresolved{ .bytes = ip.bytes, .interface_name = null }, ip.port }) catch {}, + .ip4 => |ip| text.writer.print("tcp!{d}.{d}.{d}.{d}!{d}\n", .{ ip.bytes[0], ip.bytes[1], ip.bytes[2], ip.bytes[3], ip.port }) catch {}, + .ip6 => |ip| text.writer.print("tcp!{f}!{d}\n", .{ std.Io.net.Ip6Address.Unresolved{ .bytes = ip.bytes, .interface_name = null }, ip.port }) catch {}, }; - return text.buffered(); -} - -pub fn readListeners(p: *Pardes, req: Req) Reply { - var buf: [listeners_cap]u8 = undefined; - const out = p.fs.stage(p.gpa); - out.appendSlice(p.gpa, listenersText(p, &buf)) catch return Reply.fail(req.tag, E.NOMEM); - return tree.stagedReply(p, req); + return text.written(); } // ---- tests ---- -- cgit v1.3