diff options
Diffstat (limited to 'core/Term.zig')
| -rw-r--r-- | core/Term.zig | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/core/Term.zig b/core/Term.zig index 89773f77..aa05a68f 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -102,10 +102,9 @@ pub const State = struct { var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); const parts = try walk.load(iface.Parts, arena.allocator(), bytes[8..][0..n], null); + o.media(media); out.* = .{ .impl = try o.load(gpa, bytes[8 + n ..], &parts) }; writes +%= 1; - // A replica's (a join's, a closed terminal brought back in a step). - if (tape.replaying() or dump.terminal_gpa != null) o.direct(out.impl); } }; @@ -125,14 +124,27 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State { const o = ops orelse return error.NoTerminal; const s = try gpa.create(State); errdefer gpa.destroy(s); + o.media(media); s.* = .{ .impl = try o.open(gpa, cols, rows) }; writes +%= 1; - // A replica's emulator loads its program's images by direct data alone - // (P32): what is read off the session's machine is the session's. - if (tape.replaying()) o.direct(s.impl); return s; } +/// A kitty image's medium (a file, a temporary file, shared memory: the +/// session's machine's) as its emulator reads it, made the tape's answer +/// (P30: the device's answer as it was, as a file's bytes are): the session +/// reads it, a temporary file deleted and shared memory unlinked there once, +/// and every replica is handed the same bytes, or the same failure. Under +/// screen state a replica feeds no emulator: the read is the session's. +fn media(ctx: *const anyopaque, read: *const fn (*const anyopaque) iface.MediumError![]u8, gpa: std.mem.Allocator) iface.MediumError![]u8 { + if (tape.screenState()) return read(ctx); + return tape.valueIn(.medium, gpa, readMedium, .{ read, ctx }); +} + +fn readMedium(read: *const fn (*const anyopaque) iface.MediumError![]u8, ctx: *const anyopaque) iface.MediumError![]u8 { + return read(ctx); +} + /// It and what it holds, freed, all of it with its own allocator (the /// one it was opened with): the allocator a caller hands is not used. pub fn close(s: *State, _: std.mem.Allocator) void { |
