diff options
Diffstat (limited to 'src/ninep/pty.zig')
| -rw-r--r-- | src/ninep/pty.zig | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 7333fac7..be85a497 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -137,9 +137,9 @@ pub fn readStatus(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { // Busy is what a run written now would be told: a command is running // or a line is typed at the prompt. Before the shell's first prompt a // run waits for it rather than answer busy, so that is not busy. - const marks = if (pane.terminal) |state| &state.stream.handler else null; + const marks = pardes.Term.prompt(pane.terminal); const busy = p.hostTtyTaken(id) or (!pane.fs.unmarked and (waitingRun(p, pane) != null or - (if (marks) |m| m.prompts > 0 and (m.phase != .input or !pardes.panes.terminal.promptInputEmpty(pane)) else false))); + (marks.prompts > 0 and (marks.phase != .input or !marks.input_empty)))); const out = p.fs.stage(p.gpa); const size = winsize(pane); out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch return Reply.fail(req.tag, E.NOMEM); @@ -219,8 +219,8 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { if (std.mem.trim(u8, line, " \t").len == 0) return tree.failText(req.tag, E.INVAL, e_bad_line); for (line) |c| if (c < ' ' and c != '\t') return tree.failText(req.tag, E.INVAL, e_bad_line); const pf = &pane.fs; - const state = pane.terminal orelse return tree.failText(req.tag, E.INVAL, e_bad_line); - const marks = &state.stream.handler; + if (pane.terminal == null) return tree.failText(req.tag, E.INVAL, e_bad_line); + const marks = pardes.Term.prompt(pane.terminal); if (pane.shell_failed) { // Its shell never started: no prompt is coming to wait for. answer(p, slot, "error shell gone", .{}); @@ -230,18 +230,18 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { } else if (pf.unmarked) { answer(p, slot, "error no prompt marks", .{}); } else if (waitingRun(p, pane) != null or (marks.prompts > 0 and (marks.phase != .input or - !pardes.panes.terminal.promptInputEmpty(pane) or p.hostTtyTaken(id)))) + !marks.input_empty or p.hostTtyTaken(id)))) { // Something is running or someone has typed at the prompt: sending // now would type into the middle of it. The phase is pardes's own // marks: a nested shell's prompt (ssh, a shell with its own - // integration) looks like an empty prompt to ghostty but is not the + // integration) looks like an empty prompt to the emulator but is not the // shell this run knows. // Naming what runs, where the host can tell (Linux). var name: [64]u8 = undefined; if (p.hostForegroundName(id, &name)) |program| answer(p, slot, "busy: {s} is running", .{program}) - else if (pardes.panes.terminal.onAlternateScreen(pane)) + else if (pardes.Term.modes(pane.terminal).alternate) answer(p, slot, "busy alternate screen", .{}) else answer(p, slot, "busy", .{}); @@ -285,27 +285,27 @@ pub fn readRun(p: *Pardes, req: Req) Reply { /// for the prompt means whoever reads the answer can send the next command /// at once instead of finding the shell still drawing it. pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { - const state = pane.terminal orelse return; + if (pane.terminal == null) return; const pf = &pane.fs; const slot = waitingRun(p, pane) orelse return; - const marks = &state.stream.handler; + const marks = pardes.Term.prompt(pane.terminal); if (slot.phase == .waiting) { if (pf.unmarked) { answer(p, slot, "error no prompt marks", .{}); pf.run = null; return; } - if (marks.phase != .input or !pardes.panes.terminal.promptInputEmpty(pane) or p.hostTtyTaken(id)) return; + if (marks.phase != .input or !marks.input_empty or p.hostTtyTaken(id)) return; slot.want = marks.started +% 1; slot.prompts = marks.prompts; slot.declined = marks.declined; // A prompt on the alternate screen (its program killed there): the // emulator leaves it first, as a reused command pane does, so the // run's output lands on the primary screen and is read whole. - if (pardes.panes.terminal.onAlternateScreen(pane)) pardes.panes.terminal.feedOutput(p, pane, "\x1b[?1049l"); + if (pardes.Term.modes(pane.terminal).alternate) pane.feedOutput(p, "\x1b[?1049l"); p.emitWrite(id, slot.line); p.emitWrite(id, "\r"); - pardes.panes.terminal.noteCommand(pane, slot.line); + pane.noteCommand(slot.line); // The run is the shell's first command: a greeting `ls` typed at the // same prompt would run after it, and its C would be taken for ours. pane.greet = false; @@ -322,7 +322,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { // typed into an empty prompt, so throw it away with Ctrl-C, which // drops the whole pending command, and answer at the prompt after // that, so the next line finds the shell clear. - const empty = pardes.panes.terminal.promptInputEmpty(pane); + const empty = marks.input_empty; switch (slot.cleared) { .no => { if (marks.continuation) { @@ -365,7 +365,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void { // 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). + // pins in pages it never had (the emulator'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", .{}); // Keep the tail, cut at a line start so the first line kept is whole. @@ -398,9 +398,9 @@ fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void { pub const Printed = struct { text: []const u8, whole: bool }; -/// What pane `pane`'s command printed (terminal.commandOutput), in `arena`. +/// What pane `pane`'s command printed (Term.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; + const out = pardes.Term.commandOutput(pane.terminal, arena, output_rows) catch return null; return .{ .text = out.text, .whole = out.whole }; } @@ -413,7 +413,7 @@ pub fn shellExited(p: *Pardes, pane: *Pane, status: ?u8) void { const code = status orelse return; if (waitingRun(p, pane)) |slot| if (slot.phase == .sent) { pane.fs.run = null; - pardes.panes.terminal.endOutputHere(pane); + if (pane.terminal) |state| pardes.Term.endOutputHere(state); finish(p, slot, pane, code); }; var buf: [4]u8 = undefined; @@ -507,7 +507,7 @@ test "a pane that is not a terminal has no pty/ at all" { var buf: [32]th.Dirent = undefined; const files = th.dirents(rdir(p, dir, 0).bytes, &buf); - try testing.expectEqual(@as(usize, 18), files.len); + try testing.expectEqual(@as(usize, 19), files.len); try testing.expect(th.nameAt(files, "pty") == null); try testing.expectEqual(E.NOENT, look_up(p, dir, "pty_ctl").errno()); @@ -528,7 +528,7 @@ test "a terminal pane's pty/ holds exactly ctl, status and data" { var buf: [32]th.Dirent = undefined; const files = th.dirents(rdir(p, dir, 0).bytes, &buf); - try testing.expectEqual(@as(usize, 19), files.len); + try testing.expectEqual(@as(usize, 20), files.len); try testing.expect(th.nameAt(files, "pty").?.dir); const inside = th.dirents(rdir(p, Node.of(serial, .pty), 0).bytes, &buf); @@ -962,6 +962,7 @@ test "run on a command pane says no shell is there" { test "a run's answer says cut when its output's start is gone, and reads a bounded tail" { const gpa = testing.allocator; + if (pardes.Term.ops == null) return error.SkipZigTest; // it reads the emulator const p = try withTerm(gpa); defer p.deinit(); const node = Node.of(serialOf(p), .pty_run); @@ -1005,10 +1006,10 @@ test "a run's answer says cut when its output's start is gone, and reads a bound // A resize between its start and end reflows the pins with the text. h = sh.send(p, node); sh.put(p, c ++ "one\r\ntwo\r\n"); - pardes.panes.terminal.resizeGrid(pane, 50, 20); + pane.resizeGrid(50, 20); sh.put(p, d ++ prompt); try testing.expectEqualStrings("exit 0\none\ntwo\n", sh.answered(p, node, h, into)); - pardes.panes.terminal.resizeGrid(pane, pane.cols, pane.rows); + pane.resizeGrid(pane.cols, pane.rows); // A full-screen program leaves nothing on the primary screen, and a D // with no status is not a success. @@ -1023,7 +1024,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound sh.put(p, c ++ "\x1b[?1049hhtop's screen\r\n"); _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h }); sh.put(p, "\x1b]133;D;137;aid=pardes\x07" ++ prompt); - try testing.expect(pardes.panes.terminal.onAlternateScreen(pane)); + try testing.expect(pardes.Term.modes(pane.terminal).alternate); try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(serialOf(p), .pty_status), 0, 64).bytes, " 0\n")); h = sh.send(p, node); sh.put(p, c ++ "after htop\r\n" ++ d ++ prompt); @@ -1048,7 +1049,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound _ = std.fmt.bufPrint(&line, "{d:0>8}", .{i}) catch unreachable; sh.put(p, &line); } - try testing.expect(!pane.terminal.?.stream.handler.out_start.?.garbage); + try testing.expect(!pardes.Term.emulatorOf(pane.terminal.?).stream.handler.out_start.?.garbage); sh.put(p, d ++ prompt); got = sh.answered(p, node, h, into); try testing.expect(std.mem.startsWith(u8, got, "exit 0 cut\n")); @@ -1061,14 +1062,14 @@ test "a run's answer says cut when its output's start is gone, and reads a bound const q = try withTerm(gpa); defer q.deinit(); const kept = q.panes[0].?; - kept.terminal.?.vt.screens.get(.primary).?.pages.limits.set(.bytes, 1); + pardes.Term.emulatorOf(kept.terminal.?).vt.screens.get(.primary).?.pages.limits.set(.bytes, 1); const run = Node.of(serialOf(q), .pty_run); sh.put(q, prompt); h = sh.send(q, run); sh.put(q, c); const lines = std.mem.asBytes(&@as([64][8]u8, @splat("pruned\r\n".*))); var fed: usize = 0; - while (!kept.terminal.?.stream.handler.out_start.?.garbage) : (fed += 1) { + while (!pardes.Term.emulatorOf(kept.terminal.?).stream.handler.out_start.?.garbage) : (fed += 1) { if (fed == 1000) return error.TestUnexpectedResult; sh.put(q, lines); } |
