summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:32:48 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit1d382a3ed42788e82301d0ce2a16ebc35c79046c (patch)
tree2da33a886055944f17dc7e6c53cdc0aa49735c97 /src/ninep
parent9c2fc736b9ccd7b7eea11e7f544ed540d2d2a6c2 (diff)
downloadpardes-1d382a3ed42788e82301d0ce2a16ebc35c79046c.tar.gz
pardes-1d382a3ed42788e82301d0ce2a16ebc35c79046c.zip
Term: prompt and commands through the interface: Term.prompt is the plain record of where the shell is in its command cycle (its phase, commands started, prompts drawn, lines declined, a continuation, the last command to finish and its status, input ready, input empty, the cursor at a prompt), Term.commandOutput what the newest command printed and Term.endOutputHere ends a command's output at the cursor; the pending command queue is the core's (Pane.pending_command, Pane.queuePendingCommand and Pane.releasePendingCommand, released at the shell's start or its prompt where Core.zig hears of them), and so are Pane.greeting, Pane.noteCommand, Kill's "the command pardes typed runs" (builtins.zig) and the newlines that keep a command's output below the edit copy (exec.zig); /pty/status, /pty/run and predicted echo read the record; promptInputReady, promptInputEmpty, commandRunning, armShellSpawn, shellSpawned, deinitPendingCommand and padOutputBelowEdits go; nothing else changes
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/pty.zig26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index 8e71a2c9..bd090dfc 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,7 +230,7 @@ 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
@@ -285,17 +285,17 @@ 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;
@@ -305,7 +305,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void {
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) {
@@ -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;