diff options
Diffstat (limited to 'build')
| -rw-r--r-- | build/patches.zig | 37 | ||||
| -rw-r--r-- | build/patches/ghostty_kitty.zig | 21 |
2 files changed, 58 insertions, 0 deletions
diff --git a/build/patches.zig b/build/patches.zig index 3d956d26..7c7b2d60 100644 --- a/build/patches.zig +++ b/build/patches.zig @@ -213,8 +213,45 @@ pub fn zstbi(b: *std.Build, patch: *std.Build.Step.Compile, zstbi_dep: *std.Buil /// - an image may be no larger than a screen's storage /// (TerminalImages.storage_limit) rather than ghostty's 400 MB, which a /// program could make pardes read and hold before refusing it. +/// - a medium's bytes (t=f, t=t, t=s) are had through `read_medium` when +/// the host sets one, which is handed ghostty's own read: pardes makes +/// that read a recorded answer, so a session reads a file once (deletes +/// a temporary file, unlinks shared memory, once) and every replica of +/// it is handed the same bytes or the same failure, never reading its +/// own machine (core/Term.zig `media`; docs/ghostty-kitty-medium.md). const ghostty_kitty = [_]Edit{ .{ + .old = " /// Initialize a chunked immage from the first image transmission.\n", + .new = + \\ /// pardes (build/patches.zig): how a file's, a temporary file's or + \\ /// shared memory's bytes are had: `read(ctx)` is ghostty's own read + \\ /// (which deletes a temporary file and unlinks shared memory), its + \\ /// bytes `alloc`'s; null, it is made as it is. + \\ pub var read_medium: ?*const fn (ctx: *const anyopaque, read: *const fn (ctx: *const anyopaque) MediumError![]u8, alloc: Allocator) MediumError![]u8 = null; + \\ pub const MediumError = error{ OutOfMemory, InvalidData, UnsupportedMedium, DimensionsTooLarge, TemporaryFileNotInTempDir, TemporaryFileNotNamedCorrectly }; + \\ + \\ /// Initialize a chunked immage from the first image transmission. + \\ + , + }, + .{ + .old = + \\ switch (t.medium) { + \\ .direct => unreachable, // handled above + \\ .file => try result.readFile(.file, io, alloc, t, cmd.data), + \\ .temporary_file => try result.readFile(.temporary_file, io, alloc, t, cmd.data), + \\ .shared_memory => try result.readSharedMemory(io, alloc, t, cmd.data), + \\ } + \\ + , + .new = + \\ // pardes (build/patches.zig): through the host's `read_medium`. + \\ const medium: PardesMedium = .{ .loading = &result, .io = io, .alloc = alloc, .t = t, .path = cmd.data }; + \\ result.data = .fromOwnedSlice(if (read_medium) |read| try read(&medium, PardesMedium.read, alloc) else try PardesMedium.read(&medium)); + \\ + , + }, + .{ .old = "const max_size = 400 * 1024 * 1024; // 400MB", .new = "const max_size = 64 * 1024 * 1024; // pardes (build.zig): a screen's storage, TerminalImages.storage_limit", }, diff --git a/build/patches/ghostty_kitty.zig b/build/patches/ghostty_kitty.zig index a86d62d3..870c51e1 100644 --- a/build/patches/ghostty_kitty.zig +++ b/build/patches/ghostty_kitty.zig @@ -13,3 +13,24 @@ fn pardesOpenRegular(io: std.Io, path: []const u8) !std.Io.File { const same = std.fmt.bufPrint(&buf, "/proc/self/fd/{d}", .{probe.handle}) catch unreachable; return std.Io.Dir.cwd().openFile(io, same, .{}); } + +/// pardes (build.zig): a medium's read as ghostty makes it, handed to the +/// host's `LoadingImage.read_medium`: its bytes, the caller's. +const PardesMedium = struct { + loading: *LoadingImage, + io: std.Io, + alloc: Allocator, + t: command.Transmission, + path: []const u8, + + fn read(ctx: *const anyopaque) LoadingImage.MediumError![]u8 { + const m: *const PardesMedium = @ptrCast(@alignCast(ctx)); + switch (m.t.medium) { + .direct => unreachable, // read by the caller + .file => try m.loading.readFile(.file, m.io, m.alloc, m.t, m.path), + .temporary_file => try m.loading.readFile(.temporary_file, m.io, m.alloc, m.t, m.path), + .shared_memory => try m.loading.readSharedMemory(m.io, m.alloc, m.t, m.path), + } + return m.loading.data.toOwnedSlice(m.alloc); + } +}; |
