diff options
Diffstat (limited to 'src/ninep/ctl.zig')
| -rw-r--r-- | src/ninep/ctl.zig | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index c3c70667..0f22614c 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -122,6 +122,28 @@ const Messages = struct { } }; +/// How much of `data` is whole messages, as `Messages` reads them: lines +/// ended by a newline, an Edit block only once it closes. The rest waits +/// for more (tree.Open.pending). +pub fn completeEnd(p: *Pardes, data: []const u8) usize { + const sam = @import("../sam_edit.zig"); + const edit = "Edit"; + var whole: usize = 0; + var at: usize = 0; + while (std.mem.indexOfScalarPos(u8, data, at, '\n')) |nl| { + const start = at; + var end = nl; + const first = std.mem.trim(u8, data[start..end], " \t\r"); + if (std.mem.startsWith(u8, first, edit) and (first.len == edit.len or first[edit.len] == ' ' or first[edit.len] == '\t')) { + while (sam.needsMore(p.scratch.allocator(), std.mem.trim(u8, data[start..end], " \t\r")[edit.len..])) + end = std.mem.indexOfScalarPos(u8, data, end + 1, '\n') orelse return whole; + } + at = end + 1; + whole = at; + } + return whole; +} + // ---- look and exec ---- /// One command per line, checked whole before any line runs: a line is the @@ -161,11 +183,21 @@ pub fn resultsLen(p: *Pardes) u64 { return n; } +/// The panes the open's last write touched (tree.Open.results); with no +/// open, the session's last. pub fn readResults(p: *Pardes, req: Req) Reply { const out = p.fs.stage(p.gpa); - for (p.fs.results[0..p.fs.results_len]) |serial| + const o = tree.openOf(p, req); + const kept = if (o) |open| open.results.list[0..open.results.len] else p.fs.results[0..p.fs.results_len]; + for (kept) |serial| out.print(p.gpa, "{d}\n", .{serial}) catch return Reply.fail(req.tag, E.NOMEM); - return tree.stagedReply(p, req); + const open = o orelse return tree.stagedReply(p, req); + if (!open.results.wrote) return tree.stagedReply(p, req); + var at = req; + at.off = open.results.read; + const reply = tree.stagedReply(p, at); + open.results.read += reply.payload.staged; + return reply; } // ---- /status ---- |
