From 3eb166e287ec5afbd54b03a86711610e1b5269b6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 05:48:20 -0300 Subject: panes: exec.noteRun and exec.commandDone become Pane methods (pane.noteRun, pane.commandDone) at the end of the Pane struct, beside the command_* fields they keep, since they act on one command pane; commandDone takes the pane its two callers in Core already hold, with its id for the close and the report, in place of looking it up again Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Core.zig | 4 ++-- src/exec.zig | 38 ++------------------------------------ src/look.zig | 2 +- src/ninep/pty.zig | 2 +- src/panes.zig | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/Core.zig b/src/Core.zig index 643ba4ae..c5187616 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -1277,7 +1277,7 @@ pub fn shellFailed(p: *Pardes, id: u8, err: anyerror) void { // hears one, its tag stops saying it runs, and Kill finds nothing. if (pane.command != null and !pane.command_done) { pane.command_pty = false; - exec.commandDone(p, id, 127); + pane.commandDone(p, id, 127); } else if (pane.command == null and !pane.had_shell) { // A Term whose shell never ran: no dead pane left behind; the // write that asked for it has failed with why. A terminal whose @@ -1607,7 +1607,7 @@ pub fn update(p: *Pardes, ev: Event) void { if (pane.command == null) ctlfs.pty.shellExited(p, pane, e.status) else if (!pane.command_done) - exec.commandDone(p, e.pane, e.status); + pane.commandDone(p, e.pane, e.status); }, .eof => |e| if (p.panes[e.pane]) |pane| if (pane.command != null) { // Output is over; the command is over when its child exits. diff --git a/src/exec.zig b/src/exec.zig index d0bee0e9..96902889 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -771,7 +771,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { echoCommand(p, pane, line); pane.command_from = winid(p, src); p.emitSpawn(id, pane.serial, pane.cwdSlice()); - noteRun(p, pane, "run", line); + pane.noteRun(p, "run", line); return id; } const free = p.freeSlot() orelse { @@ -789,7 +789,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { p.reportError(from, "exec", error.NoPaneRoom); return null; } - noteRun(p, pane, "run", line); + pane.noteRun(p, "run", line); return free; } @@ -824,40 +824,6 @@ fn echoCommand(p: *Pardes, pane: *Pane, line: []const u8) void { panes.terminal.feedOutput(p, pane, w.buffered()); } -/// `run ` or `exit ` in the log. -/// The whole line, one record as `msg` carries its text: its control -/// characters, a newline too, become spaces (events.pushLog). A new pane is -/// announced first, so `new` comes before the `run` in it. -pub fn noteRun(p: *Pardes, pane: *Pane, what: []const u8, said: []const u8) void { - pardes.ctlfs.events.announce(p); - var buf: pardes.Kind.Buf(command_max + 16) = .{}; - pardes.ctlfs.events.notePath(p, what, buf.print("{d} {s}", .{ pane.serial, std.mem.trim(u8, said, " \t\r\n") })); -} - -/// A command pane's child is gone: the pane stays, showing what it said -/// and how it ended, and is the next command's for its directory. -pub fn commandDone(p: *Pardes, id: usize, status: ?u8) void { - const pane = p.panes[id] orelse return; - pane.command_done = true; - // A REPL it was is gone with its command; the pane's next is not one. - pane.repl = null; - pane.command_status = status; - pane.body.mode = .normal; - // Look's `git show`: its output went to a +Pager, the +Diff now; only a - // failure is worth the pane. - if (pane.command_pages) { - pane.command_pages = false; - if (status == 0) return p.removePane(id, null) catch |err| p.reportError(id, "close", err); - } - var buf: [16]u8 = undefined; - const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 - var said: pardes.Kind.Buf(32) = .{}; - const lead = if (panes.terminal.gridCursor(pane).x != 0) "\r\n" else ""; - panes.terminal.feedOutput(p, pane, said.print("{s}exit {s}\r\n", .{ lead, code })); - noteRun(p, pane, "exit", code); - p.needs_frame = true; -} - /// Trim and unwrap clickable command-word notation once for every command /// consumer, so startup lines and interactive Exec speak the same syntax. pub fn commandText(txt: []const u8) []const u8 { diff --git a/src/look.zig b/src/look.zig index d9a850d7..6ecebd41 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1113,7 +1113,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: /// A commit hash (7 to 40 hex digits, a letter and a digit among them) /// looked at inside a git repository: `git show` it, paged into a +Pager, /// which stacks its hunks in a +Diff (ctl.fillPager); the command pane -/// goes when it succeeds (exec.commandDone). +/// goes when it succeeds (Pane.commandDone). // ponytail: a hex word that names no commit leaves git's error in a command pane, not a search; check the object first if that bites. fn lookCommit(p: *Pardes, id: usize, pane: *Pane, word: []const u8) bool { if (!isCommitHash(word)) return false; diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 8514c669..7333fac7 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -418,7 +418,7 @@ pub fn shellExited(p: *Pardes, pane: *Pane, status: ?u8) void { }; var buf: [4]u8 = undefined; // unreachable: a u8 exit code is at most 3 digits - pardes.exec.noteRun(p, pane, "exit", std.fmt.bufPrint(&buf, "{d}", .{code}) catch unreachable); + pane.noteRun(p, "exit", std.fmt.bufPrint(&buf, "{d}", .{code}) catch unreachable); } /// The pane closed or its shell was replaced: the command's end will never diff --git a/src/panes.zig b/src/panes.zig index 3bac74ab..99652b04 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -680,6 +680,39 @@ pub const Pane = struct { } pane.body.cur_pinned = true; } + + /// `run ` or `exit ` in the log. + /// The whole line, one record as `msg` carries its text: its control + /// characters, a newline too, become spaces (events.pushLog). A new pane is + /// announced first, so `new` comes before the `run` in it. + pub fn noteRun(pane: *Pane, p: *Pardes, what: []const u8, said: []const u8) void { + pardes.ctlfs.events.announce(p); + var buf: pardes.Kind.Buf(exec.command_max + 16) = .{}; + pardes.ctlfs.events.notePath(p, what, buf.print("{d} {s}", .{ pane.serial, std.mem.trim(u8, said, " \t\r\n") })); + } + + /// A command pane's child is gone: the pane stays, showing what it said + /// and how it ended, and is the next command's for its directory. + pub fn commandDone(pane: *Pane, p: *Pardes, id: usize, status: ?u8) void { + pane.command_done = true; + // A REPL it was is gone with its command; the pane's next is not one. + pane.repl = null; + pane.command_status = status; + pane.body.mode = .normal; + // Look's `git show`: its output went to a +Pager, the +Diff now; only a + // failure is worth the pane. + if (pane.command_pages) { + pane.command_pages = false; + if (status == 0) return p.removePane(id, null) catch |err| p.reportError(id, "close", err); + } + var buf: [16]u8 = undefined; + const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 + var said: pardes.Kind.Buf(32) = .{}; + const lead = if (panes.terminal.gridCursor(pane).x != 0) "\r\n" else ""; + panes.terminal.feedOutput(p, pane, said.print("{s}exit {s}\r\n", .{ lead, code })); + pane.noteRun(p, "exit", code); + p.needs_frame = true; + } }; pub const Text = @import("Text.zig"); -- cgit v1.3