summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 23:15:39 -0300
committerGabriel Schneider <[email protected]>2026-11-09 23:15:53 -0300
commit0b4cfd4b416d03ef64ccd908dfee810c6a498569 (patch)
tree83da4851e30b4dd0e788b66f0024d5b55eaee421 /src/dump.zig
parent7e6fc8c9f62bc3dc08e24856cc647fa0adefb32c (diff)
downloadpardes-0b4cfd4b416d03ef64ccd908dfee810c6a498569.tar.gz
pardes-0b4cfd4b416d03ef64ccd908dfee810c6a498569.zip
a session's end leaves a slim dump and History lists them, the tags gain Follow, History and the window's Fonts: every way out (Exit, the last pane's Del, the host's quit) runs Pardes.endSession, which puts a dump of the session in the state file under the usual label before quitting, slim by the dump's own means (dumpJoin's slim_terminals, and Store's slim-file swap now a Slim struct: no undo, a clean file's text read from its file again by revivePane, a terminal a size for a new shell), none for a session of shells alone; the dump's image carries the panes' names, which /dumps rows end with; the History builtin (SPC f h) lists the state file's dumps in a +History pane and a look at a row is a Restore of its label; the default tags: Follow after Collapse on text panes, History before Debug on the workspace row, Fonts after Themes in a window's view alone (tagline.topbarDefault picks the row per view; both rows are known defaults to the docs and tutor tests); the tty goldens re-recorded (the new words; a narrow pane's tag wraps to a second row, so its body rows shift), builtins JSON regenerated
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig85
1 files changed, 68 insertions, 17 deletions
diff --git a/src/dump.zig b/src/dump.zig
index 82b55ae6..517544fa 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -112,6 +112,55 @@ pub fn dumpState(p: *Pardes) !void {
p.emit(.write_dump);
}
+/// A session's end leaves what it was in the state file under the usual
+/// label (Pardes.endSession): its panes with their files, directories and
+/// places, slim: not a clean file's text (its file's), an undo history or
+/// a terminal's screen (the session's), so History brings a day's panes
+/// back by name. A session of shells alone leaves nothing.
+pub fn dumpExit(p: *Pardes) !void {
+ var worth = false;
+ for (p.panes) |slot| if (slot) |pane| {
+ if (pane.addon != null or (pane.file != null and pane.file.?.output == null)) worth = true;
+ };
+ if (!worth) return;
+ // The state file's, whatever the last `Dump export` named.
+ if (p.dump_export) |old| p.gpa.free(old);
+ p.dump_export = null;
+ slim_terminals = true;
+ defer slim_terminals = false;
+ var slims: [MAX_PANES]Slim = undefined;
+ var n: usize = 0;
+ defer for (slims[0..n]) |*s| s.put();
+ for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| {
+ slims[n] = Slim.take(f);
+ n += 1;
+ };
+ try dumpState(p);
+}
+
+/// A file kept slim in a dump (`dumpExit`, a closed pane's past its bound,
+/// Store.zig): without its undo, and a clean file on disk without its
+/// text, which `revivePane` reads from its file again.
+const Slim = struct {
+ f: *pardes.panes.File.State,
+ history: *pardes.panes.File.History,
+ content: []u8,
+
+ var empty: pardes.panes.File.History = .{};
+
+ fn take(f: *pardes.panes.File.State) Slim {
+ const s: Slim = .{ .f = f, .history = f.history, .content = f.content };
+ f.history = &empty;
+ if (f.output == null and f.revision == f.saved_revision and filesystem.localPath(f.path) != null) f.content = &.{};
+ return s;
+ }
+
+ fn put(s: *Slim) void {
+ s.f.history = s.history;
+ s.f.content = s.content;
+ }
+};
+
/// A Dump: into the state file, or (`Dump export`) a file of its own at
/// `to` (`~` the home directory).
pub fn dumpTo(p: *Pardes, to: ?[]const u8) !void {
@@ -168,9 +217,17 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
const mounts: []const filesystem.Mount = p.fs.mounts.items;
var on_disk: OnDisk = @splat(false);
var panes: u64 = 0;
+ // What the panes show, a word each (History's row): a file's or a
+ // kind's path, a terminal's directory.
+ var names: std.Io.Writer.Allocating = .init(gpa);
+ defer names.deinit();
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
on.* = onDisk(pane);
panes += 1;
+ const shown: []const u8 = if (pane.addon) |k| k.path else if (pane.file) |f| (if (f.output == null) f.path else "") else pane.cwdSlice();
+ if (shown.len == 0 or names.written().len + shown.len > 4096) continue;
+ if (names.written().len > 0) try names.writer.writeByte(' ');
+ try names.writer.writeAll(shown);
};
const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name;
const others = try views.dumped(p, gpa);
@@ -195,7 +252,7 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
try ctx.w.member(root, "shares", []const views.Shares, ctx.others);
}
}{ .w = &w, .p = p, .mounts = &mounts, .on_disk = &on_disk, .theme = &theme, .others = &kept });
- return pardes.Db.image(gpa, name, buf.written(), w.blobs.items, panes);
+ return pardes.Db.image(gpa, name, buf.written(), w.blobs.items, panes, names.written());
}
/// A dump for a screen-state replica's join (src/replica.zig): its blobs'
@@ -209,7 +266,7 @@ pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![
return dumpWith(p, deferred);
}
-/// `dumpJoin`'s: a terminal dumps its size, not its emulator.
+/// `dumpJoin`'s and `dumpExit`'s: a terminal dumps its size, not its emulator.
pub var slim_terminals = false;
fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
@@ -610,6 +667,13 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
if (pane.pdf) |old| return revivePdf(p, id, pane, old);
const f = if (pane.file) |*file| file else return;
if (f.output != null or filesystem.localPath(f.path) == null) return;
+ // A clean file kept slim (`Slim`): its text is its file's. One gone
+ // since is said deleted below, its text nowhere now.
+ if (f.content.len == 0 and (f.saved_len orelse 0) > 0) {
+ if (filesystem.read(p, f.path)) |text| {
+ f.content = text;
+ } else |_| {}
+ }
p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
@@ -644,15 +708,8 @@ pub fn savePane(gpa: std.mem.Allocator, pane: *pardes.panes.Pane, slim: bool) ![
if (!slim) return walk.save(pardes.panes.Pane, gpa, pane);
pane.terminal = null;
const f = if (pane.file) |*file| file else return walk.save(pardes.panes.Pane, gpa, pane);
- const history = f.history;
- const content = f.content;
- defer {
- f.history = history;
- f.content = content;
- }
- var empty: pardes.panes.File.History = .{};
- f.history = &empty;
- if (f.output == null and f.revision == f.saved_revision and filesystem.localPath(f.path) != null) f.content = &.{};
+ var slimmed = Slim.take(f);
+ defer slimmed.put();
return walk.save(pardes.panes.Pane, gpa, pane);
}
@@ -676,12 +733,6 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane {
pane.places.from = 0;
pane.collapsed = false;
pane.prompt_view = p.live;
- if (pane.file) |*f| if (f.content.len == 0 and (f.saved_len orelse 0) > 0) {
- // A clean file kept slim: its text is its file's.
- if (filesystem.read(p, f.path)) |text| {
- f.content = text;
- } else |_| {}
- };
try ensureKind(p, pane);
p.installPane(id, pane);
revivePane(p, id, pane, false);