summaryrefslogtreecommitdiff
path: root/src/ninep/pty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/pty.zig')
-rw-r--r--src/ninep/pty.zig16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index d80f7175..ee8c618e 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -86,7 +86,7 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
if (comptime pardes.hosted) if (!apply and std.mem.eql(u8, line, "exec")) if (p.panes[id]) |pane| {
const bin = pane.shell orelse p.shellBin();
var why: [320]u8 = undefined;
- if (@import("../host_io.zig").Shell.refusal(bin[0..@min(bin.len, 200)], &why)) |refused|
+ if (pardes.tape.value(.shell, @import("../host_io.zig").Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused}) catch "exec: no such shell");
};
if (!verb(p, id, line, apply)) return tree.failText(req.tag, E.INVAL, if (tooFewRows(line)) e_winsize_rows else if (outOfRange(line)) e_winsize_range else e_bad_pty_ctl);
@@ -378,9 +378,11 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void {
/// Answers a run whose command ended with `status`: the header and the
/// output it printed.
fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void {
- const printed = pardes.panes.terminal.commandOutput(pane, p.gpa, output_rows) catch
+ // As the authority's emulator has it (taped): a screen-state replica's
+ // is its deltas', which a lagging client's can be states behind, its
+ // pins in pages it never had (ghostty's leftWrap overflowed on one).
+ const printed = pardes.tape.value(.prompt, printedBy, .{ pane, p.scratch.allocator() }) orelse
return answer(p, slot, "error out of memory", .{});
- defer p.gpa.free(printed.text);
// Keep the tail, cut at a line start so the first line kept is whole.
var keep: []const u8 = printed.text;
if (keep.len > output_cap) {
@@ -409,6 +411,14 @@ fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void {
answer(p, slot, "exit {s}", .{status});
}
+pub const Printed = struct { text: []const u8, whole: bool };
+
+/// What pane `pane`'s command printed (terminal.commandOutput), in `arena`.
+fn printedBy(pane: *Pane, arena: std.mem.Allocator) ?Printed {
+ const out = pardes.panes.terminal.commandOutput(pane, arena, output_rows) catch return null;
+ return .{ .text = out.text, .whole = out.whole };
+}
+
/// The shell itself exited (a run's `exit 3`, or one typed): a run waiting
/// on the command it ran answers with the shell's status and what it
/// printed, and the log says `exit` before the pane's `del`. Unknown, the