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/CHANGELOG.md | 10 +++++++ src/Core.zig | 25 +++++++++++------ src/Db.zig | 44 ++++++++++++++++++----------- src/Effect.zig | 4 +-- src/Handover.zig | 2 +- src/Output.zig | 17 ++++++++++++ src/builtins.zig | 18 +++++++++++- src/config.zig | 17 ++++++++---- src/dump.zig | 85 ++++++++++++++++++++++++++++++++++++++++++++------------ src/look.zig | 15 ++++++++++ src/mouse.zig | 3 +- src/panes.zig | 2 +- src/tagline.zig | 13 +++++++-- src/tutor.txt | 6 ++-- 14 files changed, 204 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 2dca1ac0..0d45f0b0 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,16 @@ ## Unreleased +- A session's end (`Exit`, the last pane's `Del`, its terminal or window + gone) leaves a slim dump in the state file: its panes with their files, + directories and places, not a clean file's text, an undo history or a + terminal's screen. `History` (`SPC f h`) lists the state file's dumps in a + `+History` pane, a row each with the panes' names; a look at a row is a + `Restore` of it. `/dumps` rows end with the names too. The workspace row + has `History` before `Debug`, and a window's `Fonts` after `Themes`. + +- `Follow` is in a text pane's tag by default, after `Collapse`. + - `Follow` (`SPC c f`), Emacs's follow-mode: one text across a chain of panes as consecutive pages, each a Zerox twin in the column to the right (a new column when there is none). The pages scroll as one, and the diff --git a/src/Core.zig b/src/Core.zig index 6c5f5470..2e17b495 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -177,7 +177,6 @@ pub const View = struct { clip_pending: ?edit.ClipRequest = null, }; - gpa: std.mem.Allocator, image_gpa: std.mem.Allocator, /// Its kinds of pane (Kind.zig): the compiled-in ones, then what addons @@ -402,18 +401,19 @@ diff_output: pardes.panes.File.DiffOutput = .{}, pub const replica = .{ .local = .{ // A frame, and the timings that make it. - "surface", "frames", "chrome", - "frame_arena", "scratch", - "needs_frame", "present_skipped", - "echo", + "surface", "frames", "chrome", + "frame_arena", "scratch", "needs_frame", + "present_skipped", "echo", // Drained by every pump before its digest; a replica's queues // are its own. - "effects", "effects_head", "effects_len", "in_q", "in_head", "in_len", + "effects", + "effects_head", "effects_len", "in_q", + "in_head", "in_len", // The views no frontend here draws (views.zig). - "undrawn", + "undrawn", // How this process was started, and the last dump it made for // its host to write: a session loaded elsewhere has its own. - "opts", "dump_out", "dump_export", + "opts", "dump_out", "dump_export", }, .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" }, // The host's handles, the 9P server's fids and log, the state file @@ -801,6 +801,15 @@ pub fn deinit(p: *Pardes) void { gpa.destroy(p); } +/// The session ends: what it was goes to the state file (dump.dumpExit), +/// then the host's loop sees `quit`. Every way out comes here: Exit, the +/// last pane's Del, the host's own end (its terminal hung up, its window +/// closed). A dump that fails is said as Exit's, in the log. +pub fn endSession(p: *Pardes) void { + pardes.dump.dumpExit(p) catch |err| p.reportError(p.view().active, "Exit", err); + p.quit = true; +} + /// shell feedback after write_dump: remember where the dump landed (the /// topbar grows a `Restore ` word pointing at it) pub fn setLastDump(p: *Pardes, path: []const u8) void { 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, }); } } diff --git a/src/Effect.zig b/src/Effect.zig index a97a280c..2af28dd7 100644 --- a/src/Effect.zig +++ b/src/Effect.zig @@ -244,7 +244,7 @@ pub fn perform(p: *Pardes, e: Effect) void { .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()), .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token), // the loop's own condition; a host tears down after its own loop - .quit => p.quit = true, + .quit => p.endSession(), } } @@ -610,7 +610,7 @@ test "Save reaches every tagline with text behind it and no other" { // A scratch is an output buffer that wears the FILE tails. out.file.?.output = .{ .from = .{ .cmd = std.meta.stringToEnum(pardes.Builtin, "New").? } }; - try std.testing.expectEqualStrings(" Save Term Collapse Del", tagline.curTail(out)); + try std.testing.expectEqualStrings(" Save Term Collapse Follow Del", tagline.curTail(out)); // An image's bytes on disk already are what they are: nothing of the // pane's own is unwritten, so the word is absent and inert. diff --git a/src/Handover.zig b/src/Handover.zig index cf672ba4..2f5689f2 100644 --- a/src/Handover.zig +++ b/src/Handover.zig @@ -218,7 +218,7 @@ fn dumpCarried(p: *Pardes, kind: Kind, at: usize, ids: []const usize, seq: u32) } }{ .w = &w, .value = &value }); var name: [32]u8 = undefined; - return pardes.Db.image(p.gpa, std.fmt.bufPrint(&name, "handover-{d}", .{seq}) catch unreachable, buf.written(), w.blobs.items, ids.len); // a u32 fits 32 + return pardes.Db.image(p.gpa, std.fmt.bufPrint(&name, "handover-{d}", .{seq}) catch unreachable, buf.written(), w.blobs.items, ids.len, ""); // a u32 fits 32 } /// Whether `bytes` are a handover's dump (`dumpCarried`'s, or an older diff --git a/src/Output.zig b/src/Output.zig index 0161878e..a38245c7 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -570,6 +570,23 @@ pub fn openJumps(p: *Pardes, id: usize) !void { try refillOrOpen(p, id, .{ .cmd = .Jumplist }, try out.toOwnedSlice()); } +/// The state file's dumps as rows (Db.listDumps: label, date, size, pane +/// count, the panes' names), the newest first; a look at a row is a +/// Restore of its label (look.zig). Asked of the authority: the state file +/// is its host's. +pub fn openHistory(p: *Pardes, id: usize) !void { + const text = pardes.tape.authority(dumpsText, .{p}) orelse return error.NoStateFile; + if (text.len == 0) return error.NoDumps; + try refillOrOpen(p, id, .{ .cmd = .History }, try p.gpa.dupe(u8, text)); +} + +/// Db.listDumps's text, the step's (scratch); null for no state file. +fn dumpsText(p: *Pardes) ?[]const u8 { + var out: std.Io.Writer.Allocating = .init(p.scratch.allocator()); + p.db.listDumps(p, &out.writer) catch return null; + return out.written(); +} + /// The recent list as rows: `:: open|closed`, most recent /// first; a look at a row opens the file there, as a +Jumps row does. pub fn recentText(p: *Pardes, w: *std.Io.Writer, look_rows: bool) !void { diff --git a/src/builtins.zig b/src/builtins.zig index e021dd6b..1356874a 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -405,7 +405,7 @@ pub const Exit = struct { pub const scope: Scope = .session; pub fn run(c: Ctx) void { if (warnModifiedIn(c, .Exit, .all)) return; - c.p.quit = true; + c.p.endSession(); c.p.emit(.quit); } }; @@ -1700,6 +1700,22 @@ pub const Recent = struct { } }; +/// List the state file's dumps, those Dump made and those every session's +/// end left (dump.dumpExit), the newest first: a row each, its label, +/// date, size, pane count and the panes' names; a look at a row is a +/// Restore of its label. +pub const History = struct { + pub const scope: Scope = .session; + pub const output: OutputTraits = .{ .name = config.history_buffer }; + pub fn run(c: Ctx) void { + panes.Output.openHistory(c.p, c.id) catch |err| switch (err) { + error.NoStateFile => c.p.reportFailure(c.id, "History: no state file to list (DumpDir)"), + error.NoDumps => c.p.reportFailure(c.id, "History: no dumps yet"), + else => c.p.reportError(c.id, "History", err), + }; + } +}; + /// List the places jumped from, each a place to go. pub const Jumplist = struct { pub const scope: Scope = .session; diff --git a/src/config.zig b/src/config.zig index 96a5f557..3a846206 100644 --- a/src/config.zig +++ b/src/config.zig @@ -141,6 +141,7 @@ pub const leader_path = paths: { .Forward = "ji", .Last = "jj", .Jumplist = "jl", + .History = "fh", .Look = null, .Mini = null, .Exec = null, @@ -230,14 +231,18 @@ pub const child_term = "xterm-256color"; pub const child_colorterm = "truecolor"; pub const child_term_program = "pardes"; -pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit"; +// Fonts is the window's word alone (the font picker), so a terminal build's +// row has no such builtin to name: the window's row and the terminal's. +pub const topbar_window_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Fonts Config History Debug Exit"; +pub const topbar_terminal_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit"; +pub const topbar_str = if (@import("builtins.zig").capabilities.font_picker) topbar_window_str else topbar_terminal_str; -pub const pane_builtins_str = "Term Collapse Del"; -pub const file_pane_builtins_str = "Save Term Collapse Del"; +pub const pane_builtins_str = "Term Collapse Follow Del"; +pub const file_pane_builtins_str = "Save Term Collapse Follow Del"; /// After a file's, on one a language server speaks for. pub const lsp_pane_builtins_str = "Def Refs"; /// A diff's (a .diff, a .patch, a +Pager holding one): Diff. -pub const diff_pane_builtins_str = "Save Term Diff Collapse Del"; +pub const diff_pane_builtins_str = "Save Term Diff Collapse Follow Del"; /// A +Pager's (`pardes -`): Filter, as a terminal's. pub const pager_pane_builtins_str = "Save Term Filter Collapse Del"; /// A +Pager holding a diff (`git show`): Diff too. @@ -431,6 +436,7 @@ pub const search_buffer = "+Search"; pub const help_buffer = "+Help"; pub const dump_config_buffer = "+DumpConfig"; pub const jumps_buffer = "+Jumps"; +pub const history_buffer = "+History"; pub const preview_buffer = "+Preview"; pub const unsaved_buffer = "+Unsaved"; pub const themes_buffer = "+Themes"; @@ -1544,7 +1550,8 @@ const doc_typ = struct { if (w.end > 0) w.writeByte(' ') catch return false; w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false; } - const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; + // Both rows: the docs and the tutor show the window's and the terminal's. + const tags = [_][]const u8{ topbar_window_str, topbar_terminal_str, @import("tagline.zig").column_tag_default, pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true; // A kind's pane's: Term, its addon's words, Collapse Del (Kind.zig). const shown = w.buffered(); 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 = ∅ + 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 = ∅ - 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); diff --git a/src/look.zig b/src/look.zig index bde63bf3..be102339 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1359,6 +1359,13 @@ fn isRecentList(pane: *const Pane) bool { return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist }); } +/// Whether `pane` is the History list, whose rows name dumps. +fn isHistoryList(pane: *const Pane) bool { + const f = pane.file orelse return false; + const o = f.output orelse return false; + return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .History }); +} + // ---- a look on a diff line ---- /// The lines of a pane showing a diff, a .diff or .patch file or a @@ -1493,6 +1500,14 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { var home_buf: [4096]u8 = undefined; const stripped = std.mem.trim(u8, operand_raw, " \t\r\n"); const operand = if (stripped.len > 0 and stripped[0] == '~') filesystem.expandHome(stripped, &home_buf) else std.mem.trimEnd(u8, operand_raw, "\r\n"); + // A +History row names a dump of the state file's (its label, first): + // a look at it is a Restore of that dump; its other words are looked + // as any (a path in it opens). + if (isHistoryList(pane)) { + const row = std.mem.trim(u8, operand, " \t\r\n"); + const label = row[0 .. std.mem.indexOfAny(u8, row, " \t") orelse row.len]; + if (std.mem.startsWith(u8, label, "pardes-")) return exec.runBuiltin(p, .Restore, id, "Restore", label); + } // A +Recent row is a remembered place: reopened and clamped to the file // as it is now, never a miss for a line the file no longer has. if (isRecentList(pane)) { diff --git a/src/mouse.zig b/src/mouse.zig index c3cf64af..783b12b7 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1521,7 +1521,8 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on test "plain left click clears explicit modal selection" { const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .cols = 40, .rows = 10 }); + // Wide enough for the tag on one row: the body starts under it. + const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 10 }); defer p.deinit(); const pane = try p.setTestFile("abcdef\n"); pane.body.cur_row = 0; diff --git a/src/panes.zig b/src/panes.zig index f1bb46c8..02d5024a 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -999,7 +999,7 @@ pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void { if (v.active != id) return; // No pane left: the session is over. v.active = gainer orelse beside orelse anyPane(p) orelse { - p.quit = true; + p.endSession(); return p.emit(.quit); }; if (emptied) |c| if (v.header == null) tagline.enterHeader(p, c); diff --git a/src/tagline.zig b/src/tagline.zig index a7438be3..fa5246c4 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -52,8 +52,17 @@ pub const column_tag_default = "New Term Find Grep Joincol Delcol"; /// fixed builtins, plus `Restore ` once a dump exists. pub fn headerDefault(p: *Pardes, what: Text.What) []const u8 { if (what == .column) return column_tag_default; - const d = p.last_dump orelse return config.topbar_str; - return std.fmt.allocPrint(p.scratch.allocator(), config.topbar_str ++ " Restore {s}", .{d}) catch config.topbar_str; + const row = topbarDefault(p); + const d = p.last_dump orelse return row; + return std.fmt.allocPrint(p.scratch.allocator(), "{s} Restore {s}", .{ row, d }) catch row; +} + +/// The workspace row's words for this view: the window's row, with Fonts, +/// in a window's view alone; a terminal's view (a terminal's build, or a +/// terminal's replica of a window's session) has the row without it. +fn topbarDefault(p: *Pardes) []const u8 { + if (comptime @import("builtins.zig").capabilities.font_picker) if (@import("builtins.zig").registry.here(p, .Fonts)) return config.topbar_window_str; + return config.topbar_terminal_str; } /// the topbar line -- render and click dispatch must agree on this exact diff --git a/src/tutor.txt b/src/tutor.txt index 1de2a4e6..5b0fd23d 100644 --- a/src/tutor.txt +++ b/src/tutor.txt @@ -59,12 +59,12 @@ The workspace tag, a column's, and a file's, a terminal's, a PDF's and an image's: -| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol -| Save Term Collapse Del +| Save Term Collapse Follow Del | Term Save Mode Filter Collapse Del | Term PdfSections PdfTint PdfFit Collapse Del -| Term Collapse Del +| Term Collapse Follow Del 1. Press : here: the keyboard goes to this pane's tag, on `Save`. Press A, type a space and Help, press Esc, then Tab: `Help` -- cgit v1.3