summaryrefslogtreecommitdiff
path: root/src/Output.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/Output.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/Output.zig')
-rw-r--r--src/Output.zig69
1 files changed, 25 insertions, 44 deletions
diff --git a/src/Output.zig b/src/Output.zig
index a17b0459..7c8b7f59 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -7,7 +7,6 @@ const exec = @import("exec.zig");
const config = @import("config.zig");
const Pardes = pardes.Pardes;
const modal = @import("modal.zig");
-const dump = @import("dump.zig");
const limits = @import("memory.zig").limits;
const builtins = @import("builtins.zig");
const effect_sources = @import("effect_sources.zig");
@@ -40,9 +39,11 @@ pub const Origin = union(enum) {
preview,
};
-pub const max_arg = dump.max_origin_arg;
+/// An output's argument is typed in the bounded one-line tag storage.
+pub const max_arg = limits.max_tag_tail;
pub const State = struct {
+ pub const replica = .{ .len = .{.{ "arg_buf", "arg_len" }} };
from: Origin,
arg_buf: [max_arg]u8 = undefined,
arg_len: u16 = 0,
@@ -319,36 +320,6 @@ pub fn grain(out: ?State) Grain {
return if (tr.steps) .line else .word;
}
-pub fn word(o: Origin) []const u8 {
- return switch (o) {
- .cmd => |b| @tagName(b),
- .query => |k| @tagName(k),
- .search => "/",
- .errors => config.errors_buffer,
- .pdf_links => config.pdf_links_buffer,
- .unsaved => config.unsaved_buffer,
- .dir => dir_word,
- .preview => config.preview_buffer,
- };
-}
-
-/// A directory pane's origin as a dump names it.
-const dir_word = "dir";
-
-pub fn fromWord(w: []const u8) ?Origin {
- if (w.len == 0) return null;
- if (std.mem.eql(u8, w, "/")) return .search;
- if (std.mem.eql(u8, w, config.errors_buffer)) return .errors;
- if (std.mem.eql(u8, w, config.pdf_links_buffer)) return .pdf_links;
- if (std.mem.eql(u8, w, config.unsaved_buffer)) return .unsaved;
- if (std.mem.eql(u8, w, dir_word)) return .dir;
- if (std.mem.eql(u8, w, config.preview_buffer)) return .preview;
- if (std.meta.stringToEnum(Builtin, w)) |b|
- if (builtins.registry.outputTraits(b) != null) return .{ .cmd = b };
- if (std.meta.stringToEnum(lsp.Kind, w)) |k| return .{ .query = k };
- return null;
-}
-
pub fn resultsFrom(p: *Pardes, pane: *Pane, from: Origin) bool {
const rp = p.panes[pane.search_pane orelse return false] orelse return false;
const f = rp.file orelse return false;
@@ -934,7 +905,7 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void {
look.armLookWalk(p, free);
}
-fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
+fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
const full_header = "pardes builtins, and how to run each:\nSPC and its keys, a chord, a button, the\ntopbar - or the name, executed anywhere.\n\n";
const group_header = "pardes builtins under SPC";
const calls_help = "\nCallstack: static caller chains,\nwith signatures and clickable call sites.\nCallers / Callees: one direction at a time.\n";
@@ -963,8 +934,10 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
}
for (pardes.builtin_rows) |row| {
// a path-less builtin filters as the empty path: in the full listing
- // (which starts with nothing) and out of every group
+ // (which starts with nothing) and out of every group; a window's own
+ // word is none in a terminal's view
if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue;
+ if (!builtins.registry.here(p, row.cmd)) continue;
try w.print("{s}\n", .{row.line});
}
if (show_calls_help) try w.writeAll(calls_help);
@@ -995,21 +968,23 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
}
pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void {
- const content = try helpContent(p.gpa, prefix);
+ const content = try helpContent(p, p.gpa, prefix);
// content is handed off unfreed on purpose: openRead adopts it or frees
// it, and nothing between the alloc above and this line can fail.
return openRead(p, id, .{ .cmd = .Help }, prefix, content);
}
test "full Help renders builtin rows, a call hierarchy guide, then language keys" {
- const content = try helpContent(std.testing.allocator, "");
+ const core = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
+ defer core.deinit();
+ const content = try helpContent(core, std.testing.allocator, "");
defer std.testing.allocator.free(content);
// FIRST blank line: the end of the header (the footer opens with one too)
const body = content[(std.mem.indexOf(u8, content, "\n\n") orelse
return error.MissingHelpHeader) + 2 ..];
var lines = std.mem.splitScalar(u8, body, '\n');
- for (pardes.builtin_rows) |row|
+ for (pardes.builtin_rows) |row| if (builtins.registry.here(core, row.cmd))
try std.testing.expectEqualStrings(row.line, lines.next() orelse
return error.MissingBuiltinHelpRow);
// The short call guide disambiguates the three related commands.
@@ -1024,12 +999,18 @@ test "full Help renders builtin rows, a call hierarchy guide, then language keys
return error.MissingLanguageKeys);
try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null);
// The language group also explains call commands, without the motion footer.
- const group = try helpContent(std.testing.allocator, "l");
+ const group = try helpContent(core, std.testing.allocator, "l");
defer std.testing.allocator.free(group);
try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null);
try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null);
}
+/// Where a dump goes by default, as the session's environment says (the
+/// authority's, `tape.authority`): in `buf`.
+fn dumpDirectory(buf: []u8) []const u8 {
+ return pardes.dump.defaultDirectory(buf) orelse "";
+}
+
pub fn openConfig(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();
@@ -1040,15 +1021,15 @@ pub fn openConfig(p: *Pardes, id: usize) !void {
try p.locations_config.write(&located.writer);
try config.Runtime.writeReport(&out.writer, .{
.locations = located.written(),
- .default_dump_dir = if (host_fs) (pardes.dump.defaultDirectory(&dir_buf) orelse "") else "",
- .startup_config_path = p.opts.startup_config_path,
- .platform = @tagName(pardes.platform),
+ .default_dump_dir = if (host_fs) pardes.tape.authority(dumpDirectory, .{@as([]u8, &dir_buf)}) else "",
+ .startup_config_path = p.startupPath(),
+ .platform = builtins.viewPlatform(p),
.theme_name = p.theme().name,
.theme_file = pardes.colors.loadedThemeFile(p),
.compiled_default_shell = config.defaultShell(),
.hover_delay_frames = config.look_preview_delay_frames,
.native_images = p.native_images,
- .capabilities = builtins.capabilities,
+ .capabilities = builtins.viewCapabilities(p),
.state = &p.settings,
});
const content = try out.toOwnedSlice();
@@ -1090,7 +1071,7 @@ pub fn openEffectCode(p: *Pardes, id: usize, argument: []const u8) !void {
.transition, .scene => {},
else => return error.NotAnEffect,
}
- if (!setting.enabled(builtins.capabilities)) return error.EffectUnavailable;
+ if (!setting.enabled(builtins.viewCapabilities(p))) return error.EffectUnavailable;
// Without -Dembed-sources the paths would name nothing this build can open.
if (!limits.embedded_sources) return error.EffectUnavailable;
const paths = effect_sources.forSetting(setting) orelse
@@ -1115,7 +1096,7 @@ pub fn resetBody(p: *Pardes, pane: *Pane) void {
pane.body.cur_col = 0;
pane.body.cur_pinned = true;
pane.hscroll = 0;
- pane.wrap_n = 0;
+ pane.geometry_key = 0;
pane.body.msel = .{};
pane.body.vsel = .{};
pane.body.nsel = 0;