//! Command structs and runtime settings form the builtin registry; bindings live in config.zig. //! //! THE CONVENTION: the `///` block right above a builtin's `pub const //! = struct` is what a USER reads, in Help, `pardes help`, /commands, //! `pardes words` and the manual's glossary (`registry.doc`): what the word //! does, its argument's forms as typed, what it does bare, where its answer //! goes, an example where the forms are not obvious. No file names, no //! "registration", no history: notes for whoever reads the code are `//` //! lines inside the struct. Its first sentence (to the first `. `) is the //! summary, at most `summary_max` bytes; a blank `///` starts a paragraph. //! The compiler holds it: a builtin with no `///`, a summary past the bound //! or a `///` naming a .zig file fails the build, naming the builtin. const std = @import("std"); const pardes = @import("root.zig"); const tagline = @import("tagline.zig"); const dump = @import("dump.zig"); const exec = @import("exec.zig"); const look = @import("look.zig"); const PlumbRules = @import("Plumb.zig"); const edit = @import("edit.zig"); const colors = @import("colors.zig"); const Pardes = pardes.Pardes; const Pane = pardes.Pane; const panes = @import("panes.zig"); const layout = @import("layout.zig"); const config = @import("config.zig"); const limits = @import("memory.zig").limits; const keys = @import("keys.zig"); const Jump = @import("Jump.zig"); /// What this build's own frontend draws and its host does: the render's. pub const frontend: config.Settings.Capabilities = .{ .font_picker = pardes.font_picker, // The tty's font belongs to its emulator. .tagline_font_size = pardes.platform != .tui, .window_opacity = pardes.platform == .gui or pardes.platform == .macos, // The grip's width, the cursor's blink and the Pet are the SDL window's. .pixels = pardes.platform == .gui, }; /// The terminal's build and the window's (docs/next-daemon.md, "Phase 6: /// GUI replica notes"): each has the other's words, which a view takes as /// its own frontend does (`viewCapabilities`), so a terminal's replica of a /// window's session steps as the window's own does, and back. pub const desktop = pardes.platform == .tui or pardes.platform == .gui; const window_capabilities: config.Settings.Capabilities = .{ .font_picker = true, .tagline_font_size = true, .window_opacity = true, .pixels = true }; const terminal_capabilities: config.Settings.Capabilities = .{ .font_picker = false, .tagline_font_size = false, .window_opacity = false, .pixels = false }; /// The words this build has: a desktop build's are the window's. pub const capabilities: config.Settings.Capabilities = if (desktop) window_capabilities else frontend; /// What the live view's frontend takes: a window's, or a terminal's /// (`Pardes.frontend`, which its client says, Event.frontend). pub fn viewCapabilities(p: *const Pardes) config.Settings.Capabilities { if (comptime !desktop) return frontend; return if (p.view().frontend.windowed) window_capabilities else terminal_capabilities; } /// The live view's frontend, by name (the Settings report's platform). pub fn viewPlatform(p: *const Pardes) []const u8 { if (comptime !desktop) return @tagName(pardes.platform); return if (p.view().frontend.windowed) "gui" else "tui"; } /// Where a builtin acts: at the pane it runs from, or on the editor as a /// whole. acme keeps its window verbs on a window's ctl and its session /// commands elsewhere, as webfs and upas/fs keep session settings on a root /// ctl; pardes's root `ctl` takes the session builtins and a pane's `ctl` /// the pane ones. A builtin says `pub const scope: Scope = .session;`, /// and every setting is one; the rest act on their pane. /// The kinds of pane a builtin may be for alone (registry.needs). pub const PaneKind = enum { terminal, image, /// An image pane, or a terminal, whose program's kitty graphics are /// pictures too. picture, /// A terminal, or a +Pager: a program's colours. program_colors, pub fn has(kind: PaneKind, pane: *const panes.Pane) bool { return switch (kind) { .terminal => pane.isTerminal(), .image => pane.addon != null, .picture => pane.addon != null or pane.isTerminal(), .program_colors => pane.isTerminal() or (pane.file != null and pane.file.?.pager), }; } pub fn noun(kind: PaneKind) []const u8 { return switch (kind) { .terminal => "a terminal", .image => "an image", .picture => "an image or a terminal", .program_colors => "a terminal or a +Pager", }; } }; pub const Scope = enum { pane, session }; pub const Ctx = struct { p: *Pardes, pane: *Pane, id: usize, txt: []const u8, arg: ?[]const u8, /// Made by a gesture on the pane's body -- a middle click, the execute /// key -- as acme's execute() asks of its Text (exec.c:122,169): an /// Exec from a body may be a bound REPL's (exec.zig routeToRepl). from_body: bool = false, }; fn isEnabled(comptime T: type) bool { return !@hasDecl(T, "enabled") or T.enabled; } /// Why `word`, a builtin some build has, is none in this one: `GUI-only` /// for the GUI's own (`gui_only`), else `not in this build`; null for a /// word that is one here, or in no build. pub fn absentWhy(name: []const u8) ?[]const u8 { @setEvalBranchQuota(20000); inline for (@typeInfo(@This()).@"struct".decl_names) |d| { if (comptime @TypeOf(@field(@This(), d)) == type) { const T = @field(@This(), d); if (comptime @typeInfo(T) == .@"struct" and @hasDecl(T, "run") and !isEnabled(T)) { if (std.mem.eql(u8, d, name)) return if (@hasDecl(T, "gui_only")) "GUI-only" else "not in this build"; } } } return null; } fn manualBuiltinList() []const type { comptime { @setEvalBranchQuota(4000); var list: []const type = &.{}; for (@typeInfo(@This()).@"struct".decl_names) |d| { if (@TypeOf(@field(@This(), d)) != type) continue; const T = @field(@This(), d); if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue; if (@TypeOf(T.run) != fn (Ctx) void) @compileError(d ++ ".run must have signature fn (Ctx) void"); list = list ++ .{T}; } return list; } } fn settingList() []const config.Settings.Setting { comptime { var list: []const config.Settings.Setting = &.{}; for (config.Settings.settings) |setting| if (setting.enabled(capabilities)) { list = list ++ .{setting}; }; return list; } } pub fn word(comptime T: type) []const u8 { const n = @typeName(T); const dot = std.mem.lastIndexOfScalar(u8, n, '.') orelse return n; return n[dot + 1 ..]; } /// A builtin's documentation (THE CONVENTION, at the top of this file). pub const Doc = struct { /// Its first sentence: a line of /commands and of `pardes words`. summary: []const u8, /// All of it, a line a paragraph, the summary first. text: []const u8, }; /// The longest summary, in bytes: a line's worth after its word. pub const summary_max = 100; /// `text`'s first sentence: to the first `.` a blank or a line's end /// follows (`a.zig@main` and `from..to` go on). fn docOf(comptime text: []const u8) Doc { for (text, 0..) |c, i| { if (c == '\n') return .{ .summary = text[0..i], .text = text }; if (c == '.' and (i + 1 == text.len or text[i + 1] == ' ' or text[i + 1] == '\n')) return .{ .summary = text[0 .. i + 1], .text = text }; } return .{ .summary = text, .text = text }; } /// The `///` lines from `from` to `to` in `source` as paragraphs: each /// line's text after `///` joined to the next by a blank, a blank `///` a /// line break. fn paragraphs(comptime source: []const u8, comptime from: usize, comptime to: usize) []const u8 { var text: []const u8 = ""; var lines = std.mem.splitScalar(u8, source[from..to], '\n'); var gap: []const u8 = ""; while (lines.next()) |line| { const said = std.mem.trim(u8, line["///".len..], " "); if (said.len == 0) { if (text.len > 0) gap = "\n"; continue; } text = text ++ (if (text.len == 0) "" else if (gap.len > 0) gap else " ") ++ said; gap = ""; } return text; } pub const OutputTraits = struct { name: []const u8, steps: bool = false, jumps: bool = false, // This producer emits location rows whose labels and source excerpts may be styled. locations: bool = false, commands: bool = false, doc: bool = false, // Saving promotes this scratch buffer into an ordinary file. saves: bool = false, }; // Keep enum-dependent signatures out of the outer declaration walk. pub const registry = struct { /// Whether builtin `b` is one the live view's frontend takes: a window's /// own words (a builtin that says `in_window`, the settings a terminal /// cannot show) in a window's view alone. The rest of a build's words are /// every view's. pub fn here(p: *const Pardes, b: Builtin()) bool { return hereFor(b, viewCapabilities(p), !desktop or p.view().frontend.windowed); } /// `here` for a frontend of these capabilities, windowed or not. pub fn hereFor(b: Builtin(), caps: config.Settings.Capabilities, windowed: bool) bool { inline for (comptime manualBuiltinList(), 0..) |T, i| if (@backingInt(b) == i) return !@hasDecl(T, "in_window") or windowed; inline for (comptime settingList(), comptime manualBuiltinList().len..) |setting, i| if (@backingInt(b) == i) return setting.enabled(caps); unreachable; } pub fn Builtin() type { // Duplicate-name validation compares every pair. @setEvalBranchQuota(200_000); const manual = manualBuiltinList(); const generated = settingList(); const count = manual.len + generated.len; const Tag = std.math.IntFittingRange(0, count - 1); var names: [count][]const u8 = undefined; for (manual, 0..) |T, i| names[i] = word(T); for (generated, manual.len..) |setting, i| names[i] = setting.word; for (names, 0..) |name, i| for (names[i + 1 ..]) |later| if (std.mem.eql(u8, name, later)) @compileError("duplicate builtin name: " ++ name); return @Enum(Tag, .exhaustive, &names, &std.simd.iota(Tag, count)); } /// What a hand-written builtin says as `name` (`pub const takes_arg = /// true;`), `default` when it says nothing, and `setting` for a setting. fn declOr(b: Builtin(), comptime name: []const u8, default: anytype, setting: @TypeOf(default)) @TypeOf(default) { inline for (comptime manualBuiltinList(), 0..) |T, i| if (@backingInt(b) == i) return if (@hasDecl(T, name)) @field(T, name) else default; return setting; } /// What a user reads of builtin `b` (THE CONVENTION, at the top). pub fn doc(b: Builtin()) Doc { return docs[@backingInt(b)]; } /// Each builtin's documentation, by its number: a hand-written one's /// the `///` block above it, read off this file at compile time; a /// setting's its `doc`. const docs = docs: { const manual = manualBuiltinList(); const generated = settingList(); var table: [manual.len + generated.len]Doc = undefined; var found: [manual.len]bool = @splat(false); // a few branches a byte of the source, once @setEvalBranchQuota(4_000_000); const source = @embedFile("builtins.zig"); var block: ?usize = null; // where the `///` lines above this one start var block_end: usize = 0; var at: usize = 0; while (at < source.len) { const end = std.mem.indexOfScalarPos(u8, source, at, '\n') orelse source.len; const line = source[at..end]; if (std.mem.startsWith(u8, line, "///")) { if (block == null) block = at; block_end = end; } else { if (block) |from| if (std.mem.startsWith(u8, line, "pub const ")) { const rest = line["pub const ".len..]; if (std.mem.indexOf(u8, rest, " = struct")) |name_end| for (manual, 0..) |T, i| { if (!std.mem.eql(u8, word(T), rest[0..name_end])) continue; table[i] = docOf(paragraphs(source, from, block_end)); found[i] = true; }; }; block = null; } at = end + 1; } for (manual, 0..) |T, i| { if (!found[i]) @compileError("builtin " ++ word(T) ++ " has no documentation: a `///` block right above `pub const " ++ word(T) ++ " = struct`"); held(word(T), table[i]); } for (generated, manual.len..) |setting, i| { table[i] = docOf(setting.doc); held(setting.word, table[i]); } break :docs table; }; /// THE CONVENTION's two rules the compiler can read. fn held(comptime name: []const u8, comptime d: Doc) void { if (d.summary.len > summary_max) @compileError(std.fmt.comptimePrint("builtin {s}: its first sentence is {d} bytes, over {d}: \"{s}\"", .{ name, d.summary.len, summary_max, d.summary })); if (std.mem.indexOf(u8, d.text, ".zig") != null) @compileError("builtin " ++ name ++ ": its documentation names a source file; a note for the code's reader is a `//` line inside the struct"); } pub fn takesArg(b: Builtin()) bool { // Every setting takes its value, and a switch flips when bare. return declOr(b, "takes_arg", false, true); } /// Whether the word takes its argument joined by a `+` as one word a /// tag can hold and a click take whole (`Term+fish`). Only a builtin /// that says `pub const plus_arg = true;`: others have arguments a `+` /// may be in (`Dump+2024.zon` is a name, not Dump's argument). pub fn plusArg(b: Builtin()) bool { return declOr(b, "plus_arg", false, false); } /// Whether the word means nothing without its argument (`Mount`, /// `Msg`, a setting's value), or would ask for it at a prompt (`Find`): /// a ctl refuses it bare before any line of the write runs. A builtin /// says `pub const requires_arg = true;` beside `takes_arg`. /// The one kind of pane a builtin means something on, or null for any: /// it says `pub const needs: PaneKind = .terminal;`, and on any other /// pane it is refused (exec.runBuiltinFrom), as Repl and Edit are. pub fn needs(b: Builtin()) ?PaneKind { return declOr(b, "needs", @as(?PaneKind, null), null); } pub fn requiresArg(b: Builtin()) bool { inline for (comptime settingList(), comptime manualBuiltinList().len..) |setting, i| if (@backingInt(b) == i) return switch (setting.action) { // a switch flips bare, a choice steps, and DumpDir and Shell bare // are the default .toggle, .dump_dir, .choice, .shell => false, .theme, .font, .tagline_size, .window_opacity, .message_linger, .inactive_dim, .grip_width => true, // bare, it says the current value (exec.applySettingBuiltin) .tab, .callstack_depth => false, }; return declOr(b, "requires_arg", false, false); } pub fn scope(b: Builtin()) Scope { return declOr(b, "scope", Scope.pane, .session); } pub fn outputTraits(b: Builtin()) ?OutputTraits { return declOr(b, "output", @as(?OutputTraits, null), null); } /// Does this builtin say its own name on the message row before it runs? /// The ones that own that row themselves declare `quiet` and do not. pub fn announces(b: Builtin()) bool { // a setting builtin changes something invisible; say so return !declOr(b, "quiet", false, false); } pub fn dispatch(b: Builtin(), c: Ctx) void { inline for (comptime manualBuiltinList(), 0..) |T, i| if (@backingInt(b) == i) return T.run(c); inline for (comptime settingList(), comptime manualBuiltinList().len..) |setting, i| if (@backingInt(b) == i) return exec.applySettingBuiltin(c.p, setting, c.arg); unreachable; } }; // ---- the two acme verbs ---- /// Look at its argument as B3 does: open the file or address it names, else /// find the word. /// /// `Look notes.txt:12` opens the file at line 12, or goes to the pane already /// showing it; an address may be a line, `:12:5`, `/re/`, a directory (a pane /// listing it) or a URL (the browser, by a plumbing rule). A relative path is /// found in the directory of the pane looked from, then of each pane on the /// jump list. Bare (Enter): the selection, else what is under the cursor. pub const Look = struct { pub const takes_arg = true; pub const requires_arg = true; // a look's answer is the pane it opens or the place it jumps to; its own // name on the message row would only be noise over that pub const quiet = true; pub fn run(c: Ctx) void { // Bare (a key bound to it, a tag's Look with nothing held): the // selection, else what Enter on the cursor takes, the one expansion. const arg = c.arg orelse (exec.currentOperand(c.p, c.pane) orelse return); look.lookAt(c.p, c.id, arg); } }; /// Run its argument as B2 on it would: a builtin, else a shell command. /// /// `Exec Newcol` runs the builtin. `Exec make test` runs the line: from a /// terminal at an idle, empty prompt, typed into its shell; from anywhere /// else, in a command pane (a terminal running `$SHELL -c` the line, which /// shows its output and `exit N` when it ends; Kill stops it). Run by name, a /// line is never a REPL's. pub const Exec = struct { pub const takes_arg = true; pub const requires_arg = true; pub fn run(c: Ctx) void { // the destination pane is Look's business (it focuses what answered); // an execute deliberately leaves you where you were _ = exec.executeFrom(c.p, c.id, c.arg orelse return, c.from_body); } }; /// Run its argument as Exec does, at the project's root. /// /// The root is the nearest directory at or above this pane's holding a /// `.jj` or a `.git`, else this pane's own. `Root make` runs make there in a /// command pane; `Root Find` and `Root Grep` (`SPC f F`, `SPC f G`) search /// from there, their heads `Find root` and `Grep root`, a Grep's leading /// directory read from the root. Bare (`SPC :`), the `:` line, its head /// `: root`, whose Enter runs the line there. pub const Root = struct { pub const takes_arg = true; pub fn run(c: Ctx) void { const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (line.len == 0) return @import("Command.zig").open(c.p, c.pane, true); c.p.exec_root = true; defer c.p.exec_root = false; _ = exec.executeFrom(c.p, c.id, line, c.from_body); } }; // ---- session ---- /// Which panes a refusal asks about: every one (Exit, Restore), one (Del), /// or a column's (Delcol). pub const Asked = union(enum) { all, pane: usize, column: usize }; /// acme's rowclean (editors/acme/wind.c:511-529, winclean), asked before /// what would throw unsaved text away: each pane holding some nobody has /// been told about is listed in +Unsaved, `: Modified`, under it /// `Exit again to discard`, with a short notice, `3 unsaved panes -- Exit /// again to discard`, /// naming the word asking, since repeating it throws the text away, and is /// then clean for the asking, as winclean clears `dirty`; so the same word /// again, with nothing edited since, goes ahead. Only the same word: a /// Restore a script was refused does not spend the warning an Exit owes /// the person at the keyboard. A scratch of under 100 bytes is no loss /// worth the question, as winclean does not ask for one. pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool { // Every pane asked about is an `unsaved ` record, as // acme's rowclean names them all (wind.c:511); the refusal a write // gets names the one, or counts them, never a list cut short. var count: usize = 0; var one_buf: [limits.host_path_cap + 24]u8 = undefined; var one: []const u8 = ""; // The whole list goes into +Unsaved, where it stays; the notice is short. var listed: std.ArrayList(u8) = .empty; const arena = c.p.scratch.allocator(); for (c.p.panes, 0..) |slot, id| { const pane = slot orelse continue; switch (which) { .all => {}, .pane => |only| if (id != only) continue, .column => |col| if ((layout.findPane(c.p, id) orelse continue).col != col) continue, } const f = pane.file orelse continue; // Twins (Zerox) hold one text: closing one while another stays // loses nothing, and the text is asked about once. if (f.twin != 0) { const asked_elsewhere = for (c.p.panes, 0..) |other_slot, other_id| { const other = other_slot orelse continue; const of = other.file orelse continue; if (other_id == id or of.twin != f.twin) continue; const closing = switch (which) { .all => true, .pane => |only| other_id == only, .column => |col| if (layout.findPane(c.p, other_id)) |at| at.col == col else false, }; if (!closing or other_id < id) break true; } else false; if (asked_elsewhere) continue; } // A +New scratch saves nowhere, but what is typed in it is as lost; // under 100 bytes it is not asked about, as acme's winclean does not // whine about a small unnamed window, nor about a command's output. const scratch = if (f.output) |o| o.from == .cmd and o.from.cmd == .New else false; // A file deleted on disk is asked about, edited or not: its text is // nowhere else now (acme's winclean asks the same). const gone = f.disk_gone and f.output == null; if (!gone) { if (f.revision == f.saved_revision or !(panes.Output.fileTraits(f.output).saves or scratch)) continue; if (f.output != null and f.content.len < 100) continue; // Dirty by a rename alone is no text to lose, as get says (ctl.zig). // Nor is a buffer never edited at all: its first edit is what keeps // the text it had (File.zig), so with none there is nothing to lose. const saved = f.saved_hash orelse continue; if (panes.File.fileHash(&f) == saved) continue; } if (pane.discard_warned) |w| if (w.revision == f.revision and w.by == asking) continue; pane.discard_warned = .{ .revision = f.revision, .by = asking }; // Scratches share a name: each is named with its pane's serial too, // `/dir/+New (pane 12)`, the same in every refusal (Exit, Restore, // Del, Delcol). var name_buf: [limits.host_path_cap + 24]u8 = undefined; const name = if (scratch) std.fmt.bufPrint(&name_buf, "{s} (pane {d})", .{ f.path, pane.serial }) catch f.path else f.path; pardes.ctlfs.events.noteLog(c.p, .unsaved, pane); listed.print(arena, "{s}: Modified\n", .{name}) catch {}; if (count == 0) one = std.fmt.bufPrint(&one_buf, "{s}", .{name}) catch name; count += 1; } if (count > 0) { listed.print(arena, "\n{s} again to discard\n", .{@tagName(asking)}) catch {}; // A refused Delcol changes nothing, the layout included: its records // and its notice say it, and no +Unsaved opens. if (asking != .Delcol) if (c.p.gpa.dupe(u8, listed.items)) |content| panes.Output.openUnsaved(c.p, c.id, content) else |_| {}; var short: pardes.Kind.Buf(96) = .{}; c.p.reportFailure(c.id, short.print("{d} unsaved pane{s} \u{2014} {s} again to discard", .{ count, if (count == 1) "" else "s", @tagName(asking) })); } if (count > 0 and (c.p.fs.no_prompt or c.p.fs.capturing)) { var said_buf: pardes.Kind.Buf(limits.host_path_cap + 96) = .{}; const said = if (count == 1) said_buf.print("{s}: Modified ({s} again to discard)", .{ one, @tagName(asking) }) else said_buf.print("{d} unsaved panes: Modified ({s} again to discard)", .{ count, @tagName(asking) }); var room: @TypeOf(c.p.fs.failure) = undefined; const kept = pardes.ctlfs.fitErr(said, &room); @memcpy(c.p.fs.failure[0..kept.len], kept); c.p.fs.failure_len = @intCast(kept.len); } return count > 0; } /// Quit the editor; refused once while a pane holds unsaved text. /// /// Each pane with unsaved text is listed in +Unsaved and the notice counts /// them; Exit again, nothing edited since, quits and discards it. On the way /// out the session's panes are kept in the state file, for History and /// Restore. pub const Exit = struct { // acme's Exit (editors/acme/exec.c:892), asking warnModifiedIn first. pub const scope: Scope = .session; pub fn run(c: Ctx) void { if (warnModifiedIn(c, .Exit, .all)) return; c.p.endSession(); c.p.emit(.quit); } }; /// Stop the commands pardes started that are still running. /// /// They are the lines pardes typed into a terminal (from an exec, a middle /// click, a pty/run) and its command panes. Bare, every one; `Kill make ls`, /// those whose line starts with one of the words. Each gets SIGTERM: a /// command pane's whole command, a terminal's foreground job, never its /// shell, which stays. pub const Kill = struct { // acme's Kill (exec.c, `kill`; acme.c's WKill) posts the "kill" note, // which ends a process; here a terminal's job between its C and D marks. pub const scope: Scope = .session; pub const takes_arg = true; pub fn run(c: Ctx) void { const names = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); var stopped = false; var jobless = false; var running = false; for (c.p.panes, 0..) |slot, id| { const pane = slot orelse continue; const command: ?[]const u8 = if (pane.command) |line| (if (pane.command_done) null else line) else null; // The command pardes last typed here, running now. const typed_runs = if (pane.sent_command) |sent| typed: { const at = panes.Term.prompt(pane.terminal); break :typed at.phase == .running and at.started == sent.seq; } else false; if (command == null and !typed_runs) continue; running = true; const first = if (command) |line| first: { const said = std.mem.trim(u8, line, " \t"); break :first said[0 .. std.mem.indexOfAny(u8, said, " \t") orelse said.len]; } else pane.sent_command.?.word[0..pane.sent_command.?.len]; if (names.len > 0) { var words = std.mem.tokenizeAny(u8, names, " \t"); while (words.next()) |w| { if (std.mem.eql(u8, w, first)) break; } else continue; } // A command pane's child is the command: the whole of its // process group goes, as acme's Kill ends the process. A // terminal's job is asked of the host now, not queued: the job // the marks say is running is the one signalled, not whatever // runs by then. if (command != null) { c.p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = .term } }); stopped = true; } else if (c.p.hostKillJob(id)) stopped = true else jobless = true; } if (stopped) return; if (jobless) return c.p.reportFailure(c.id, "Kill: no job to signal (its shell runs it without job control)"); // Said, but no failure: a script's Kill, named or not, has nothing // left to do. Only commands running, none of them the one named, is. if (names.len > 0 and running) c.p.reportFailure(c.id, "Kill: no running command has that first word") else c.p.setMessage(.at(c.id), "Kill: nothing running"); } }; /// Write the session's panes and layout to the state file, for Restore. /// /// `Dump export ` writes them to a file of their own instead (`~` the /// home directory). The workspace tag then holds a `Restore ` word that /// brings them back. pub const Dump = struct { pub const scope: Scope = .session; pub const takes_arg = true; pub fn run(c: Ctx) void { var to: ?[]const u8 = null; if (c.arg) |arg| { const trimmed = std.mem.trim(u8, arg, " \t"); if (!std.mem.startsWith(u8, trimmed, "export ")) return c.p.reportFailure(c.id, "Dump: takes export , or nothing"); const path = std.mem.trim(u8, trimmed["export".len..], " \t"); if (path.len == 0) return c.p.reportFailure(c.id, "Dump: takes export , or nothing"); to = path; } // Never a Dump said done that wrote nothing: its failure is said. dump.dumpTo(c.p, to) catch |err| c.p.reportError(.at(c.id), "Dump", err); } }; /// Replace every pane with those of a dump. /// /// `Restore