diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 02:07:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 83b9d45b8665a80bdb70934aa23bbde5cc03d202 (patch) | |
| tree | c902b557ef624b07cd139659d0a891cd4809e03e /src/builtins.zig | |
| parent | b3d32656413734952bc918c2d4cfd12fede6c214 (diff) | |
| download | pardes-83b9d45b8665a80bdb70934aa23bbde5cc03d202.tar.gz pardes-83b9d45b8665a80bdb70934aa23bbde5cc03d202.zip | |
plumber: a look sends what it looks at (docs/next-plumber.md, phase 2): after the pane's own readings and once a name already open in a pane is focused (never sent), lookAt sends the trimmed name, type text, src pardes (term from a raw terminal, a kind's name from its pane), wdir the pane's directory, with what resolveLookTarget found of it (Plumb.Seen: isfile and isdir take it, so no second stat and Look's own readings of a URL or `//` stay no file); a message the rules give back to `edit` as sent is Look's own (Sent.look) and runs lookAt's switch on that target, one nothing takes or a started word declines is Look's own too, whose `.url` arm is now the word's search; the edit port's open of another message runs with look_text, which now means "unplumbed", so the edit port's lookAt never sends again (the recursion trap); the three diff hooks become the default rules of the record's §5.2 (a bare .diff/.patch to `Diff $file`, a commit hash in the editor to `Diff $0`, after the two edit sets), and `Diff` takes a file or a revision, a rule's Diff declining in silence (Pardes.plumb_declined) where it cannot (no hunk, not readable, no .git above): hunks.lookedAt and lookedAtCommit go, their bodies in hunks.word, the `needs` check of the bare form in the word, PaneKind.diff gone; the old one-line `Plumb` word, Core.plumb, look.Port, plumbRuleError, plumbTarget and resolve's rules block go: bare, `Plumb` opens <config>/plumbing as Config opens init (both through builtins.openConfigFile; `include basic` in a new one), an argument is refused in words, Save applies it (host_io.writeFile beside reapplyInitFile, Plumb.saved), and boot reads it (Plumb.boot in applyStartupConfig); a started program now runs detached as Plan 9's plumber's (the coordinator's decision for the user's question 4): Effect.start, every host's host_io.startDetached (double fork, setsid, /dev/null for 0-2, every other fd closed, argv exec'd in wdir with no shell, the child's errno back through a close-on-exec pipe, said as `plumb start: <prog>: <why>`), so exec_dir goes; resolveLookTarget's and Plumb.Send.search's directory walk is one look.Dirs; test: look.zig's Plumb test rewritten onto the rules (a rule's word, an open pane unsent, the hover's resolve, a URL with no web rule searched for) and a hash inside and outside a git work tree; addons.zig's Plumb test onto plumb/rules (a port no kind reads, its kind gone: Look's own); Plumb.zig: the word, the save and boot; replicas.zig gains a URL (speculated whole, confirmed, no rollback) and a hash, each the authority's and a replica's own; every look golden unchanged; the reference quotes src/plumbing whole and says the order, the changelog says so
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 93 |
1 files changed, 38 insertions, 55 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index bb91d0b0..2b9d9f53 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -5,6 +5,7 @@ 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; @@ -65,8 +66,6 @@ pub const PaneKind = enum { picture, /// A terminal, or a +Pager: a program's colours. program_colors, - /// A text pane showing a diff: a .diff, a .patch, a +Pager holding one. - diff, pub fn has(kind: PaneKind, pane: *const panes.Pane) bool { return switch (kind) { @@ -74,7 +73,6 @@ pub const PaneKind = enum { .image => pane.addon != null, .picture => pane.addon != null or pane.isTerminal(), .program_colors => pane.isTerminal() or (pane.file != null and pane.file.?.pager), - .diff => @import("hunks.zig").shows(pane), }; } @@ -84,7 +82,6 @@ pub const PaneKind = enum { .image => "an image", .picture => "an image or a terminal", .program_colors => "a terminal or a +Pager", - .diff => "a diff or a +Diff", }; } }; @@ -937,43 +934,18 @@ pub const Incl = struct { } }; -/// The plumber's rules, for the session, one a line as plumb(6) orders a -/// rule: `Plumb suffix .svg to image` makes a look at an existing `.svg` -/// file an image pane. The user's rules are tried in the order given, -/// before the built-in ones, and the first that matches takes the look. -/// Bare, it lists them; `Plumb -` empties the list. +/// Open the plumbing file, the plumber's rules (plumb(6)'s rule sets) in +/// the configuration directory beside `init`: saved, they are the rules in +/// force. Not there yet, it holds `include basic`, the default rules. pub const Plumb = struct { pub const scope: Scope = .session; pub const takes_arg = true; pub fn run(c: Ctx) void { - const p = c.p; - const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (std.mem.eql(u8, typed, "-")) { - for (p.plumb.items) |rule| p.gpa.free(rule); - p.plumb.clearRetainingCapacity(); - return p.setMessage(c.id, "Plumb: none"); - } - if (typed.len > 0) { - var said: [320]u8 = undefined; - if (look.plumbRuleError(&p.kinds, typed)) |why| - return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Plumb: {s}", .{why}) catch "Plumb: invalid rule"); - // One blank between words, as the list shows it. - var rule: std.ArrayList(u8) = .empty; - defer rule.deinit(p.gpa); - var words = std.mem.tokenizeAny(u8, typed, " \t"); - while (words.next()) |w| { - if (rule.items.len > 0) rule.append(p.gpa, ' ') catch |err| return p.reportError(c.id, "Plumb", err); - rule.appendSlice(p.gpa, w) catch |err| return p.reportError(c.id, "Plumb", err); - } - p.plumb.ensureUnusedCapacity(p.gpa, 1) catch |err| return p.reportError(c.id, "Plumb", err); - p.plumb.appendAssumeCapacity(rule.toOwnedSlice(p.gpa) catch |err| return p.reportError(c.id, "Plumb", err)); - return; - } - var list: std.Io.Writer.Allocating = .init(p.scratch.allocator()); - list.writer.writeAll("Plumb:") catch |err| return p.reportError(c.id, "Plumb", err); - for (p.plumb.items, 0..) |rule, i| list.writer.print("{s} {s}", .{ if (i == 0) "" else ";", rule }) catch |err| return p.reportError(c.id, "Plumb", err); - if (p.plumb.items.len == 0) list.writer.writeAll(" none") catch |err| return p.reportError(c.id, "Plumb", err); - p.setMessage(c.id, list.written()); + if (std.mem.trim(u8, c.arg orelse "", " \t\r\n").len > 0) return c.p.reportFailure(c.id, PlumbRules.e_word); + var buf: [4096]u8 = undefined; + const path = PlumbRules.filePath(c.p, &buf) orelse + return c.p.reportFailure(c.id, "Plumb: no plumbing file here: no configuration directory"); + openConfigFile(c, "Plumb", path, "include basic\n"); } }; @@ -1087,11 +1059,11 @@ pub const Filter = struct { } }; -/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. +/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. `Diff <file>` stacks that diff's, `Diff <revision>` git show's. /// The diff viewer's one registration: its word and traits here, all else /// its own (hunks.zig). pub const Diff = struct { - pub const needs: PaneKind = .diff; + pub const takes_arg = true; pub const output: OutputTraits = .{ .name = config.diff_buffer, .steps = true, .locations = true }; pub const run = @import("hunks.zig").word; }; @@ -1334,25 +1306,36 @@ pub const Config = struct { pub fn run(c: Ctx) void { const path = c.p.startupPath() orelse return c.p.reportFailure(c.id, "Config: no startup file here: no configuration directory"); - var real_buf: [4096]u8 = undefined; - const real = if (pardes.filesystem.resolveOs(path, &real_buf)) |r| r.path else null; - for (c.p.panes, 0..) |slot, id| { - const pane = slot orelse continue; - const f = pane.file orelse continue; - if (f.output != null) continue; - if (!std.mem.eql(u8, f.path, path) and !(if (real) |r| std.mem.eql(u8, f.path, r) else false)) continue; - return look.focusPaneLine(c.p, id, .{}, .keep); - } - if (real != null) return look.lookAt(c.p, c.id, path); - // Not there yet: a pane named for it, which Save makes. - const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Config", error.NoPaneSlots); - panes.newScratchFor(c.p, c.id, .scratch); - if (c.p.panes[free] == null) return; - @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, "Config", err); - c.p.view().active = free; + openConfigFile(c, "Config", path, ""); } }; +/// A file of the configuration directory's (Config's init, Plumb's +/// plumbing) in a pane: its pane when it is open, else the file, else a +/// pane of that name holding `initial`, for Save to make it and its +/// directory. +fn openConfigFile(c: Ctx, name: []const u8, path: []const u8, initial: []const u8) void { + var real_buf: [4096]u8 = undefined; + const real = if (pardes.filesystem.resolveOs(path, &real_buf)) |r| r.path else null; + for (c.p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const f = pane.file orelse continue; + if (f.output != null) continue; + if (!std.mem.eql(u8, f.path, path) and !(if (real) |r| std.mem.eql(u8, f.path, r) else false)) continue; + return look.focusPaneLine(c.p, id, .{}, .keep); + } + if (real != null) return look.lookAt(c.p, c.id, path); + // Not there yet: a pane named for it, which Save makes. + const free = c.p.freeSlot() orelse return c.p.reportError(c.id, name, error.NoPaneSlots); + panes.newScratchFor(c.p, c.id, .scratch); + const made = c.p.panes[free] orelse return; + @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, name, err); + if (initial.len > 0) if (made.file) |*f| { + _ = panes.File.replace(c.p, f, 0, f.content.len, initial); + }; + c.p.view().active = free; +} + /// Open the settings in effect, each a word to click, and the startup /// file's path. pub const DumpConfig = struct { |
