summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 239edeaf..69ac3113 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);
@@ -912,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;
}
@@ -1665,8 +1710,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;