diff options
Diffstat (limited to 'src/Store.zig')
| -rw-r--r-- | src/Store.zig | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/src/Store.zig b/src/Store.zig index 856a7fc1..95f5368f 100644 --- a/src/Store.zig +++ b/src/Store.zig @@ -498,31 +498,30 @@ pub fn keep(s: *Store, p: *Pardes, id: usize) ?Kept { const pane = p.panes[id] orelse return null; if (pane.fs.unannounced or pane.query != null) return null; if (pane.file) |f| if (f.output) |o| if (o.from == .preview) return null; - // An output pane's record holds its text whole (base64): one past the - // bound is known before a dump of it is made, which for a 256 MiB - // +Pager held the session up for seconds only to be thrown away. + // An output pane's record holds its text whole: one past the bound is + // known before a dump of it is made, which for a 256 MiB +Pager held + // the session up for seconds only to be thrown away. if (pane.file) |f| if (f.output != null and f.content.len > max_record) return null; const gpa = p.recentGpa(); - const arena = p.scratch.allocator(); - var dp = dump.dumpPane(p, arena, pane) catch return null; - var zon = oneDump(p, arena, dp) catch return null; - // A terminal's history is what makes it big: kept without it, it comes - // back a fresh shell in its directory. - if (zon.len > max_record) if (dp.terminal) |*t| { - t.stream = ""; - t.stream_b64 = ""; - dp.body = ""; - zon = oneDump(p, arena, dp) catch return null; - }; - if (zon.len > max_record) return null; + var owned = dump.savePane(gpa, pane, false) catch return null; + // A terminal's history or a file's undo is what makes it big: kept + // without them it comes back a fresh shell in its directory, or its + // file as it is on disk. + if (owned.len > max_record) { + gpa.free(owned); + owned = dump.savePane(gpa, pane, true) catch return null; + } + if (owned.len > max_record) { + gpa.free(owned); + return null; + } const what: []const u8 = if (pane.file) |f| f.path else if (pane.pdfPath()) |pdf| pdf else if (pane.image) |iv| iv.path else if (pane.command) |c| c else pane.cwdSlice(); - var name = gpa.alloc(u8, @min(what.len, 4096)) catch return null; - // One line, a tab its end: a newline or a tab in it is a space. - for (what[0..name.len], 0..) |c, i| name[i] = if (c == '\n' or c == '\t') ' ' else c; - const owned = gpa.dupe(u8, zon) catch { - gpa.free(name); + var name = gpa.alloc(u8, @min(what.len, 4096)) catch { + gpa.free(owned); return null; }; + // One line, a tab its end: a newline or a tab in it is a space. + for (what[0..name.len], 0..) |c, i| name[i] = if (c == '\n' or c == '\t') ' ' else c; const at = layout.findPane(p, id); const owner = layout.ownerOf(p, id); return .{ @@ -552,18 +551,6 @@ pub const Kept = struct { } }; -/// A Dump of the one pane `dp`, as a Restore would read it. -fn oneDump(p: *Pardes, arena: std.mem.Allocator, dp: dump.Pane) ![]const u8 { - const ids = [_]usize{0}; - const columns = [_]dump.Column{.{ .panes = &ids }}; - const one = [_]dump.Pane{dp}; - const state: dump.State = .{ .screen = .{ .cols = p.screen_w, .rows = p.screen_h }, .columns = &columns, .panes = &one }; - try dump.validate(state); - var out: std.Io.Writer.Allocating = .init(arena); - try std.zon.stringify.serialize(state, .{}, &out.writer); - return out.written(); -} - /// The pane `k` kept is gone, its rows given to `gainer` (a slot, after /// they moved; null none): listed, and its record framed for the store. pub fn close(s: *Store, p: *Pardes, k: Kept, gainer: ?usize) void { @@ -805,18 +792,14 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool { // Read from the file: this call's to free (`unlist` frees one held). defer if (place.body.len == 0) gpa.free(body); const m = parseMeta(body) orelse return false; - var parsed = dump.readZon(p.gpa, body[m.dump_at..], "closed pane") catch return false; - defer parsed.deinit(); const free = p.freeSlot() orelse { p.reportError(from, "Panes", error.NoPaneSlots); return false; }; - const src = parsed.value.panes[0]; - const pane = dump.restorePane(p, free, src) catch |err| { + _ = dump.loadPane(p, free, body[m.dump_at..]) catch |err| { p.reportError(from, "Panes", err); return false; }; - pane.collapsed = false; const owner = if (place.owner != 0) p.paneBySerial(place.owner) else null; const gainer = if (place.gainer != 0) p.paneBySerial(place.gainer) else null; const placed = if (owner) |o| |
