summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
committerGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
commita479792a1ab2b593642d7f648194bfa23ce01dba (patch)
tree96ddee7d879a9084daa07db43b0b7910b072a785 /src/builtins.zig
parente179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff)
parent4c761893e5b3fdae422622cfa02104ab36633045 (diff)
downloadpardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz
pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig144
1 files changed, 88 insertions, 56 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 1f1e674e..38a4d835 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -16,7 +16,8 @@ const builtin = @import("builtin");
const Header = @import("esp32p4_gpio.zig").Header;
const limits = @import("memory.zig").limits;
-pub const capabilities: config.Runtime.Capabilities = .{
+/// What this build's own frontend draws and its host does: the render's.
+pub const frontend: config.Runtime.Capabilities = .{
.font_picker = pardes.font_picker,
.panel_transitions = pardes.hosted,
.scene_shaders = pardes.platform == .gui or pardes.platform == .macos,
@@ -32,6 +33,30 @@ pub const capabilities: config.Runtime.Capabilities = .{
.lift = 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 == .tty or pardes.platform == .gui;
+const window_capabilities: config.Runtime.Capabilities = .{ .font_picker = true, .panel_transitions = true, .scene_shaders = true, .tagline_font_size = true, .window_opacity = true, .window_blur = false, .ligatures = true, .lift = true };
+const terminal_capabilities: config.Runtime.Capabilities = .{ .font_picker = false, .panel_transitions = true, .scene_shaders = false, .tagline_font_size = false, .window_opacity = false, .window_blur = false, .ligatures = false, .lift = false };
+
+/// The words this build has: a desktop build's are the window's.
+pub const capabilities: config.Runtime.Capabilities = if (desktop) window_capabilities else frontend;
+
+/// What the live view's frontend takes: a window's, or a terminal's
+/// (`Pardes.windowed`, which its client says, Event.frontend).
+pub fn viewCapabilities(p: *const Pardes) config.Runtime.Capabilities {
+ if (comptime !desktop) return frontend;
+ return if (p.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.windowed) "gui" else "tty";
+}
+
/// 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
@@ -93,6 +118,7 @@ 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.
@@ -155,6 +181,21 @@ pub const OutputTraits = struct {
// 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.windowed);
+ }
+
+ /// `here` for a frontend of these capabilities, windowed or not.
+ pub fn hereFor(b: Builtin(), caps: config.Runtime.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);
@@ -453,11 +494,14 @@ test "Look does not announce itself on the message row; Del still does" {
}
test "Ligatures is a setting only in the shell that shapes text" {
- const exists = @hasField(registry.Builtin(), "Ligatures");
- try std.testing.expectEqual(pardes.platform == .gui, exists);
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- try std.testing.expectEqual(exists, p.executeBuiltinLine(p.active, "Ligatures off"));
+ // A desktop build has the word, which a window's view takes alone.
+ try std.testing.expectEqual(desktop, @hasField(registry.Builtin(), "Ligatures"));
+ const exists = registry.here(p, .Ligatures);
+ try std.testing.expectEqual(pardes.platform == .gui, exists);
+ // Taken either way: run, or said to be GUI-only.
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Ligatures off"));
try std.testing.expectEqual(!exists, p.settings.ligatures);
var storage: [8192]u8 = undefined;
var out: std.Io.Writer = .fixed(&storage);
@@ -468,7 +512,7 @@ test "Ligatures is a setting only in the shell that shapes text" {
.compiled_default_shell = config.defaultShell(),
.hover_delay_frames = null,
.native_images = false,
- .capabilities = capabilities,
+ .capabilities = viewCapabilities(p),
.state = &p.settings,
});
try std.testing.expectEqual(exists, std.mem.indexOf(u8, storage[0..out.end], "Ligatures off\n") != null);
@@ -725,7 +769,7 @@ pub const Restore = struct {
var why_buf: [256]u8 = undefined;
pardes.dump.check(c.p.gpa, bytes, &why_buf) catch |err| {
var buf: [limits.host_path_cap + 320]u8 = undefined;
- const why = if (err == error.ParseZon) why_buf[0..std.mem.indexOfScalar(u8, &why_buf, 0).?] else pardes.Messages.errorWords(err, &why_buf);
+ const why = if (err == error.OutOfMemory) pardes.Messages.errorWords(err, &why_buf) else why_buf[0..std.mem.indexOfScalar(u8, &why_buf, 0).?];
return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: not a pardes dump: {s}", .{ path, why }) catch "Restore: not a pardes dump");
};
}
@@ -737,51 +781,41 @@ pub const Restore = struct {
}
};
-/// Attach this terminal to a detached pardes session by name.
-pub const Attach = struct {
+/// Detach this pardes from its terminal or window, leaving the session
+/// running: `pardes --attach` (or `pardes-gui --attach`) takes it back.
+pub const Detach = struct {
pub const scope: Scope = .session;
- pub const takes_arg = true;
pub const enabled = pardes.can_attach;
pub fn run(c: Ctx) void {
- if (comptime enabled) ask(c) else unreachable;
+ if (comptime enabled)
+ c.p.emit(.{ .detach = .{ .pane = @intCast(c.id) } })
+ else
+ unreachable;
}
- fn ask(c: Ctx) void {
- const name = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
- if (name.len > pardes.attach_name_max)
- return c.p.reportError(c.id, comptime word(@This()), error.NameTooLong);
- // A detached session has no terminal to move: bare, there is no
- // "the one session there" but itself; a name is said for what it is.
- if (c.p.opts.detached_session) {
- if (name.len == 0) return c.p.reportFailure(c.id, "wrong #args in control message \"Attach\": a detached session names the session");
- // A session is its socket, `pardes-detached-<name>.sock` beside
- // the 9P ones (detached/server.zig socketPath); not imported, as
- // the core links no frontend's code.
- const ninep_io = @import("9p_io.zig");
- var dir_buf: [ninep_io.sun_path_len:0]u8 = undefined;
- var path_buf: [ninep_io.sun_path_len + 64:0]u8 = undefined;
- const exists = if (ninep_io.socketDir(&dir_buf)) |dir|
- (if (std.fmt.bufPrintSentinel(&path_buf, "{s}/pardes-detached-{s}.sock", .{ dir, name }, 0)) |path| ninep_io.statNoFollow(path) != null else |_| false)
- else
- false;
- var said: [pardes.attach_name_max + 96]u8 = undefined;
- return c.p.reportFailure(c.id, if (exists)
- std.fmt.bufPrint(&said, "Attach: {s}: a detached session has no terminal to attach; Attach from a frontend", .{name}) catch "Attach: a detached session has no terminal to attach"
- else
- std.fmt.bufPrint(&said, "Attach: {s}: no such session", .{name}) catch "Attach: no such session");
- }
- c.p.emit(.{ .attach = .{ .pane = @intCast(c.id), .name = .from(name) } });
+};
+
+/// Take in the shells of a session that died holding them, each as a
+/// terminal pane here: the pardes daemon kept their terminals open.
+pub const Adopt = struct {
+ pub const scope: Scope = .session;
+ pub const enabled = pardes.can_attach;
+ pub fn run(c: Ctx) void {
+ if (comptime !enabled) unreachable;
+ const adopt = c.p.host.vtable.adopt orelse return c.p.reportFailure(c.id, "Adopt: no pardes daemon is keeping shells for this session");
+ adopt(c.p.host.ctx, @intCast(c.id));
}
};
-/// Detach this pardes from its terminal, leaving the session running.
-pub const Detach = struct {
+/// Move this session onto the pardes installed since it started, in place:
+/// its text, undo, views, terminals with their running shells, and its
+/// terminals and windows come along. The pardes daemon moves too.
+pub const Upgrade = struct {
pub const scope: Scope = .session;
pub const enabled = pardes.can_attach;
pub fn run(c: Ctx) void {
- if (comptime enabled)
- c.p.emit(.{ .detach = .{ .pane = @intCast(c.id) } })
- else
- unreachable;
+ if (comptime !enabled) unreachable;
+ const upgrade = c.p.host.vtable.upgrade orelse return c.p.reportFailure(c.id, "Upgrade: this pardes cannot move to another build in place");
+ upgrade(c.p.host.ctx, @intCast(c.id));
}
};
@@ -816,11 +850,7 @@ pub const Mount = struct {
};
// A mount that cannot be reached is said now, and taken back, not
// found out by the first look through it.
- const reached = reached: {
- pardes.turn.yield();
- defer pardes.turn.back();
- break :reached @import("9p_io.zig").Client.probe(c.p.gpa, dial);
- };
+ const reached = pardes.tape.site(.probe, null, @import("9p_io.zig").Client.probeMount, .{ c.p.gpa, dial });
reached catch |err| {
if (c.p.fs.mounts.pop()) |gone| {
c.p.gpa.free(gone.name);
@@ -911,7 +941,7 @@ pub const DumpThemes = struct {
pub const enabled = pardes.hosted;
pub fn run(c: Ctx) void {
if (comptime enabled) {
- if (c.p.opts.config_dir == null) {
+ if (c.p.configDir() == null) {
c.p.reportError(c.id, "dump themes", error.NoConfigDirectory);
return;
}
@@ -926,6 +956,7 @@ pub const Fonts = struct {
pub const output: OutputTraits = .{ .name = config.fonts_buffer, .steps = true, .commands = true };
pub const enabled = capabilities.font_picker;
pub const gui_only = true;
+ pub const in_window = true;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
@@ -950,11 +981,7 @@ pub const TreeContext = struct {
};
file.tree_context = on;
file.syntax_dirty = true;
- c.pane.wrap_n = 0;
- c.pane.context_rows = 0;
- c.pane.body_rows = 0;
- c.pane.body_visible_rows = 0;
- c.pane.context_row_limit = null;
+ c.pane.geometry_key = 0;
c.p.surface.body_layers[c.id].rows = 0;
}
};
@@ -1448,7 +1475,8 @@ pub const Tty = struct {
// start its fallback in its place.
if (comptime pardes.hosted) if (arg.len > 0) {
var why: [320]u8 = undefined;
- if (@import("host_io.zig").Shell.refusal(arg[0..@min(arg.len, 200)], &why)) |refused| {
+ // The authority's lookup, taped, as Shell's (exec.zig).
+ if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ arg[0..@min(arg.len, 200)], &why })) |refused| {
var said: [340]u8 = undefined;
return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Tty: {s}", .{refused}) catch "Tty: no such shell");
}
@@ -1459,8 +1487,11 @@ pub const Tty = struct {
};
/// A Linux terminal with the current session mounted through kernel v9fs.
+/// A word of every hosted build, Linux's or not: a build's words are its
+/// Help's rows, which a replica of another build's session makes as its
+/// session did (a Linux client of a FreeBSD one diverged at SPC ?).
pub const Tty9p = struct {
- pub const enabled = pardes.hosted and @import("builtin").os.tag == .linux;
+ pub const enabled = pardes.hosted;
pub fn run(c: Ctx) void {
exec.spawnV9fsTty(c.p, c.id);
}
@@ -1580,7 +1611,7 @@ pub const Help = struct {
pub const Config = struct {
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
- const path = c.p.opts.startup_config_path orelse
+ 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;
@@ -1683,8 +1714,9 @@ pub const Pet = struct {
pub const scope: Scope = .session;
pub const takes_arg = true;
pub const requires_arg = true;
- pub const enabled = pardes.platform == .gui;
+ pub const enabled = desktop;
pub const gui_only = true;
+ pub const in_window = true;
pub fn run(c: Ctx) void {
const name = std.mem.trim(u8, c.arg orelse return, " \t\r\n");
c.p.settings.pet = std.meta.stringToEnum(@TypeOf(c.p.settings.pet), name) orelse return;