From 0b4cfd4b416d03ef64ccd908dfee810c6a498569 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 23:15:39 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Db.zig | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'src/Db.zig') diff --git a/src/Db.zig b/src/Db.zig index f7966ee0..5cea5be9 100644 --- a/src/Db.zig +++ b/src/Db.zig @@ -418,7 +418,7 @@ const session_tag = "db".*; /// keeps beside it and its pane count) in a database in memory, `last` /// naming it, `gpa`'s. Of the same session, the same bytes: its ids are /// std.Io.failing's zeros, never random ones. -pub fn image(gpa: std.mem.Allocator, label: []const u8, session: []const u8, blobs: []const pardes.walk.Blob, panes: u64) ![]u8 { +pub fn image(gpa: std.mem.Allocator, label: []const u8, session: []const u8, blobs: []const pardes.walk.Blob, panes: u64, names: []const u8) ![]u8 { var buf: std.Io.Writer.Allocating = .init(gpa); errdefer buf.deinit(); var db = try Memory.init(std.Io.failing, .{ .buffer = &buf, .hash_id = hash_id, .file_id = 0 }); @@ -427,6 +427,7 @@ pub fn image(gpa: std.mem.Allocator, label: []const u8, session: []const u8, blo session: []const u8, blobs: []const pardes.walk.Blob, panes: u64, + names: []const u8, pub fn run(ctx: @This(), cursor: *Memory.Cursor(.read_write)) !void { const root = try Memory.HashMap(.read_write).init(cursor.*); try root.put(key("last"), .{ .bytes = ctx.label }); @@ -435,6 +436,7 @@ pub fn image(gpa: std.mem.Allocator, label: []const u8, session: []const u8, blo const entry = try Memory.HashMap(.read_write).init(try dumps.putCursor(key(ctx.label))); try entry.put(key("session"), .{ .bytes_object = .{ .value = ctx.session, .format_tag = session_tag } }); try entry.put(key("panes"), .{ .uint = ctx.panes }); + try entry.put(key("names"), .{ .bytes = ctx.names }); const hashes = try Memory.ArrayList(.read_write).init(try entry.putCursor(key("blobs"))); const texts = try Memory.HashMap(.read_write).init(try root.putCursor(key("blobs"))); for (ctx.blobs) |*b| { @@ -442,7 +444,7 @@ pub fn image(gpa: std.mem.Allocator, label: []const u8, session: []const u8, blo try texts.put(blobKey(&b.hash), .{ .bytes = b.bytes }); } } - }{ .label = label, .session = session, .blobs = blobs, .panes = panes }); + }{ .label = label, .session = session, .blobs = blobs, .panes = panes, .names = names }); return buf.toOwnedSlice(); } @@ -462,6 +464,8 @@ pub const Read = struct { session: Memory, label: []u8, panes: u64, + /// What its panes show, a word each (dump.image); "" in an old image. + names: []u8, /// The image `bytes` at its dump `label`, else its last one. pub fn open(gpa: std.mem.Allocator, bytes: []const u8, label: ?[]const u8) !*Read { @@ -470,7 +474,7 @@ pub const Read = struct { errdefer gpa.destroy(r); // Read, never written: the bytes are borrowed, never freed here. var borrowed: std.ArrayList(u8) = .fromOwnedSlice(@constCast(bytes)); - r.* = .{ .gpa = gpa, .image_buf = .fromArrayList(gpa, &borrowed), .image = undefined, .session_buf = undefined, .session = undefined, .label = &.{}, .panes = 0 }; + r.* = .{ .gpa = gpa, .image_buf = .fromArrayList(gpa, &borrowed), .image = undefined, .session_buf = undefined, .session = undefined, .label = &.{}, .panes = 0, .names = &.{} }; r.image = Memory.init(std.Io.failing, .{ .buffer = &r.image_buf }) catch return error.NotADump; const top = Memory.HashMap(.read_only).init(r.image.rootCursor().readOnly()) catch return error.NotADump; r.label = if (label) |l| try gpa.dupe(u8, l) else last: { @@ -480,6 +484,8 @@ pub const Read = struct { errdefer gpa.free(r.label); const entry = try entryOf(Memory, top, r.label) orelse return error.NoDump; r.panes = if (entry.getCursor(key("panes")) catch null) |c| c.readUint() catch 0 else 0; + r.names = if (entry.getCursor(key("names")) catch null) |c| @constCast(c.readBytesAlloc(gpa, 4096) catch &.{}) else &.{}; + errdefer if (r.names.len > 0) gpa.free(r.names); const at = (entry.getCursor(key("session")) catch return error.NotADump) orelse return error.NotADump; const session: []u8 = @constCast(at.readBytesAlloc(gpa, null) catch |err| return if (err == error.OutOfMemory) error.OutOfMemory else error.NotADump); var owned: std.ArrayList(u8) = .fromOwnedSlice(session); @@ -491,6 +497,7 @@ pub const Read = struct { pub fn close(r: *Read) void { r.session_buf.deinit(); + if (r.names.len > 0) r.gpa.free(r.names); r.gpa.free(r.label); r.gpa.destroy(r); } @@ -543,7 +550,7 @@ fn imageOf(o: *Open, gpa: std.mem.Allocator, label: []const u8) !?[]u8 { try blobs.append(gpa, .{ .hash = hash, .bytes = text }); } } - return try image(gpa, label, session, blobs.items, panes); + return try image(gpa, label, session, blobs.items, panes, ""); }, } } @@ -655,6 +662,7 @@ fn putLocked(o: *Open, r: *Read, label: []const u8, buf: []u8) ![]const u8 { try entry.put(key("seq"), .{ .uint = seq }); try entry.put(key("date"), .{ .uint = ctx.date }); try entry.put(key("panes"), .{ .uint = ctx.r.panes }); + try entry.put(key("names"), .{ .bytes = ctx.r.names }); var session_at = (try from.getCursor(key("session"))) orelse return error.NoDump; var size = try session_at.count(); try copyBytes(DB, &session_at, try entry.putCursor(key("session")), session_tag); @@ -738,16 +746,20 @@ fn trim(comptime DB: type, gpa: std.mem.Allocator, dumps: DB.HashMap(.read_write } /// The dumps the state file keeps, a line each, the newest first: its -/// label, its date (UTC), its size in bytes and its pane count. +/// label, its date (UTC), its size in bytes, its pane count and what its +/// panes showed, a word each. pub fn listDumps(db: *Db, p: *Pardes, w: *std.Io.Writer) !void { const o = db.opened(p) orelse return; pardes.turn.yield(); defer pardes.turn.back(); const gpa = p.recentGpa(); - const Row = struct { seq: u64, date: u64, size: u64, panes: u64, label: []u8 }; + const Row = struct { seq: u64, date: u64, size: u64, panes: u64, label: []u8, names: []u8 }; var rows: std.ArrayList(Row) = .empty; defer { - for (rows.items) |r| gpa.free(r.label); + for (rows.items) |r| { + gpa.free(r.label); + gpa.free(r.names); + } rows.deinit(gpa); } switch (o.where) { @@ -759,14 +771,14 @@ pub fn listDumps(db: *Db, p: *Pardes, w: *std.Io.Writer) !void { while (try it.next()) |kv_at| { const kv = try kv_at.readKeyValuePair(); const entry = try DB.HashMap(.read_only).init(kv.value_cursor); - var row: Row = .{ .seq = 0, .date = 0, .size = 0, .panes = 0, .label = @constCast(try kv.key_cursor.readBytesAlloc(gpa, 4096)) }; + var row: Row = .{ .seq = 0, .date = 0, .size = 0, .panes = 0, .label = @constCast(try kv.key_cursor.readBytesAlloc(gpa, 4096)), .names = &.{} }; + errdefer gpa.free(row.label); inline for (.{ "seq", "date", "size", "panes" }) |field| if (try entry.getCursor(key(field))) |c| { @field(row, field) = c.readUint() catch 0; }; - rows.append(gpa, row) catch |err| { - gpa.free(row.label); - return err; - }; + row.names = if (try entry.getCursor(key("names"))) |c| @constCast(try c.readBytesAlloc(gpa, 4096)) else try gpa.dupe(u8, ""); + errdefer gpa.free(row.names); + try rows.append(gpa, row); } }, } @@ -780,10 +792,10 @@ pub fn listDumps(db: *Db, p: *Pardes, w: *std.Io.Writer) !void { const yd = es.getEpochDay().calculateYearDay(); const md = yd.calculateMonthDay(); const ds = es.getDaySeconds(); - try w.print("{s} {d:0>4}-{d:0>2}-{d:0>2}T{d:0>2}:{d:0>2}:{d:0>2}Z {d} {d}\n", .{ - r.label, yd.year, md.month.numeric(), @as(u8, md.day_index) + 1, - ds.getHoursIntoDay(), ds.getMinutesIntoHour(), ds.getSecondsIntoMinute(), r.size, - r.panes, + try w.print("{s} {d:0>4}-{d:0>2}-{d:0>2}T{d:0>2}:{d:0>2}:{d:0>2}Z {d} {d}{s}{s}\n", .{ + r.label, yd.year, md.month.numeric(), @as(u8, md.day_index) + 1, + ds.getHoursIntoDay(), ds.getMinutesIntoHour(), ds.getSecondsIntoMinute(), r.size, + r.panes, if (r.names.len > 0) " " else "", r.names, }); } } -- cgit v1.3